mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
API, issue 1471: Allow users belonging to the docker group to use the docker client
This commit is contained in:
parent
1643943402
commit
c015d26e96
1 changed files with 15 additions and 1 deletions
16
api.go
16
api.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -974,7 +975,20 @@ func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if proto == "unix" {
|
if proto == "unix" {
|
||||||
os.Chmod(addr, 0700)
|
os.Chmod(addr, 0660)
|
||||||
|
groups, err := ioutil.ReadFile("/etc/group")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
re := regexp.MustCompile("(^|\n)docker:.*?:([0-9]+)")
|
||||||
|
if gidMatch := re.FindStringSubmatch(string(groups)); gidMatch != nil {
|
||||||
|
gid, err := strconv.Atoi(gidMatch[2])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
utils.Debugf("docker group found. gid: %d", gid)
|
||||||
|
os.Chown(addr, 0, gid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
httpSrv := http.Server{Addr: addr, Handler: r}
|
httpSrv := http.Server{Addr: addr, Handler: r}
|
||||||
return httpSrv.Serve(l)
|
return httpSrv.Serve(l)
|
||||||
|
|
Loading…
Reference in a new issue