зеркало из https://github.com/microsoft/docker.git
API, issue 1471: Allow users belonging to the docker group to use the docker client
This commit is contained in:
Родитель
1643943402
Коммит
c015d26e96
16
api.go
16
api.go
|
@ -13,6 +13,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -974,7 +975,20 @@ func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
|
|||
return e
|
||||
}
|
||||
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}
|
||||
return httpSrv.Serve(l)
|
||||
|
|
Загрузка…
Ссылка в новой задаче