Merge pull request #1592 from AkihiroSuda/workdir2

ctr run: add --cwd
This commit is contained in:
Kenfe-Mickaël Laventure 2017-10-04 09:17:21 -07:00 committed by GitHub
commit ec43dc2b46
4 changed files with 18 additions and 1 deletions

View File

@ -89,6 +89,10 @@ var runCommand = cli.Command{
Name: "checkpoint",
Usage: "provide the checkpoint digest to restore the container",
},
cli.StringFlag{
Name: "cwd",
Usage: "specify the working directory of the process",
},
}, snapshotterFlags...),
Action: func(context *cli.Context) error {
var (

View File

@ -107,6 +107,9 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
if len(args) > 0 {
opts = append(opts, containerd.WithProcessArgs(args...))
}
if cwd := context.String("cwd"); cwd != "" {
opts = append(opts, containerd.WithProcessCwd(cwd))
}
if context.Bool("tty") {
opts = append(opts, withTTY())
}

View File

@ -107,7 +107,9 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
if len(args) > 0 {
opts = append(opts, containerd.WithProcessArgs(args...))
}
if cwd := context.String("cwd"); cwd != "" {
opts = append(opts, containerd.WithProcessCwd(cwd))
}
return client.NewContainer(ctx, id,
containerd.WithNewSpec(opts...),
containerd.WithContainerLabels(labels),

View File

@ -19,6 +19,14 @@ func WithProcessArgs(args ...string) SpecOpts {
}
}
// WithProcessCwd replaces the current working directory on the generated spec
func WithProcessCwd(cwd string) SpecOpts {
return func(_ context.Context, _ *Client, _ *containers.Container, s *specs.Spec) error {
s.Process.Cwd = cwd
return nil
}
}
// WithHostname sets the container's hostname
func WithHostname(name string) SpecOpts {
return func(_ context.Context, _ *Client, _ *containers.Container, s *specs.Spec) error {