isula-build/patch/0051-bugfix-set-user-s-uid-and-gid-for-containers.patch

35 lines
1.0 KiB
Diff
Raw Normal View History

From fbd95494e6e402fd123955fbaf337696cc22c750 Mon Sep 17 00:00:00 2001
From: DCCooper <1866858@gmail.com>
Date: Mon, 31 May 2021 20:50:24 +0800
Subject: [PATCH 3/5] bugfix: set user's uid and gid for containers
Signed-off-by: DCCooper <1866858@gmail.com>
---
builder/dockerfile/run.go | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/builder/dockerfile/run.go b/builder/dockerfile/run.go
index 6c38b55..828fe67 100644
--- a/builder/dockerfile/run.go
+++ b/builder/dockerfile/run.go
@@ -95,6 +95,16 @@ func (c *cmdBuilder) setupRuntimeSpec(command []string) (*specs.Spec, error) {
}
// set specific runtime spec config
+ user := c.stage.docker.Config.User
+ if user != "" {
+ pair, err := util.GetChownOptions(user, c.stage.mountpoint)
+ if err != nil {
+ return nil, err
+ }
+ g.SetProcessUID(uint32(pair.UID))
+ g.SetProcessGID(uint32(pair.GID))
+ g.SetProcessUsername(c.stage.docker.Config.User)
+ }
g.RemoveHostname()
g.SetProcessArgs(command)
g.SetProcessTerminal(false)
--
1.8.3.1