From e74a63397028a60ae741818ae6e7f1525869242f Mon Sep 17 00:00:00 2001 From: Ales Verbic Date: Sun, 17 Mar 2024 17:05:43 -0400 Subject: [PATCH] feat: create container with current uid,gid (#119) Signed-off-by: Ales Verbic --- pkgmgr/docker.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgmgr/docker.go b/pkgmgr/docker.go index c82ccc3..2108d2f 100644 --- a/pkgmgr/docker.go +++ b/pkgmgr/docker.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "log/slog" + "os" "sort" "strings" @@ -171,6 +172,11 @@ func (d *DockerService) Create() error { if err != nil { return err } + // Set the desired user ID and group ID + userID := os.Getuid() + groupID := os.Getgid() + userAndGroup := fmt.Sprintf("%d:%d", userID, groupID) + // Create container d.logger.Debug(fmt.Sprintf("creating container %s", d.ContainerName)) resp, err := client.ContainerCreate( context.Background(), @@ -180,6 +186,7 @@ func (d *DockerService) Create() error { Entrypoint: d.Command, Cmd: d.Args, Env: tmpEnv[:], + User: userAndGroup, }, &container.HostConfig{ RestartPolicy: container.RestartPolicy{