Skip to content

Commit 09d2c46

Browse files
committed
cmd/create: Use the host's user namespace when running as root
One of the biggest advantages of running as root is the ability to have all the UIDs from the host operating system mapped into the container by using the host's user namespace. This can be a big help when faced with permission problems. #267
1 parent 25b647d commit 09d2c46

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cmd/create.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ func createContainer(container, image, release string, showCommandToEnter bool)
227227
ulimitHost = []string{"--ulimit", "host"}
228228
}
229229

230+
var usernsArg string
231+
if currentUser.Uid == "0" {
232+
usernsArg = "host"
233+
} else {
234+
usernsArg = "keep-id"
235+
}
236+
230237
dbusSystemSocket, err := getDBusSystemSocket()
231238
if err != nil {
232239
return err
@@ -376,7 +383,7 @@ func createContainer(container, image, release string, showCommandToEnter bool)
376383
createArgs = append(createArgs, ulimitHost...)
377384

378385
createArgs = append(createArgs, []string{
379-
"--userns=keep-id",
386+
"--userns", usernsArg,
380387
"--user", "root:root",
381388
"--volume", "/boot:/run/host/boot:rslave",
382389
"--volume", "/etc:/run/host/etc",

0 commit comments

Comments
 (0)