Skip to content

Commit ad836c2

Browse files
authored
Merge pull request #273 from shishir-a412ed/pid_namespace
Add --pid to enable host pid namespace.
2 parents 72ac023 + 3d83ba5 commit ad836c2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Basic flags:
255255
- :whale: `--rm`: Automatically remove the container when it exits
256256
- :whale: `--pull=(always|missing|never)`: Pull image before running
257257
- Default: "missing"
258+
- :whale: `--pid=(host)`: PID namespace to use
258259

259260
Network flags:
260261
- :whale: `--net, --network=(bridge|host|none|<CNI>)`: Connect a container to a network

cmd/nerdctl/run.go

+14
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ var runCommand = &cli.Command{
131131
Aliases: []string{"m"},
132132
Usage: "Memory limit",
133133
},
134+
// Enable host pid namespace
135+
&cli.StringFlag{
136+
Name: "pid",
137+
Usage: "PID namespace to use",
138+
},
134139
&cli.IntFlag{
135140
Name: "pids-limit",
136141
Usage: "Tune container pids limit (set -1 for unlimited)",
@@ -484,6 +489,15 @@ func runAction(clicontext *cli.Context) error {
484489
opts = append(opts, oci.WithDevShmSize(shmBytes/1024))
485490
}
486491

492+
pidNs := strings.ToLower(clicontext.String("pid"))
493+
if pidNs != "" {
494+
if pidNs != "host" {
495+
return fmt.Errorf("Invalid pid namespace. Set --pid=host to enable host pid namespace.")
496+
} else {
497+
opts = append(opts, oci.WithHostNamespace(specs.PIDNamespace))
498+
}
499+
}
500+
487501
rtCOpts, err := generateRuntimeCOpts(clicontext)
488502
if err != nil {
489503
return err

0 commit comments

Comments
 (0)