Skip to content

Commit

Permalink
Merge pull request #273 from shishir-a412ed/pid_namespace
Browse files Browse the repository at this point in the history
Add --pid to enable host pid namespace.
  • Loading branch information
AkihiroSuda authored Jun 29, 2021
2 parents 72ac023 + 3d83ba5 commit ad836c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ Basic flags:
- :whale: `--rm`: Automatically remove the container when it exits
- :whale: `--pull=(always|missing|never)`: Pull image before running
- Default: "missing"
- :whale: `--pid=(host)`: PID namespace to use

Network flags:
- :whale: `--net, --network=(bridge|host|none|<CNI>)`: Connect a container to a network
Expand Down
14 changes: 14 additions & 0 deletions cmd/nerdctl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ var runCommand = &cli.Command{
Aliases: []string{"m"},
Usage: "Memory limit",
},
// Enable host pid namespace
&cli.StringFlag{
Name: "pid",
Usage: "PID namespace to use",
},
&cli.IntFlag{
Name: "pids-limit",
Usage: "Tune container pids limit (set -1 for unlimited)",
Expand Down Expand Up @@ -484,6 +489,15 @@ func runAction(clicontext *cli.Context) error {
opts = append(opts, oci.WithDevShmSize(shmBytes/1024))
}

pidNs := strings.ToLower(clicontext.String("pid"))
if pidNs != "" {
if pidNs != "host" {
return fmt.Errorf("Invalid pid namespace. Set --pid=host to enable host pid namespace.")
} else {
opts = append(opts, oci.WithHostNamespace(specs.PIDNamespace))
}
}

rtCOpts, err := generateRuntimeCOpts(clicontext)
if err != nil {
return err
Expand Down

0 comments on commit ad836c2

Please sign in to comment.