From 36a2f3eb3d16f346ea3a52a96e36a6921a923e06 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 10 Oct 2018 19:18:29 +0900 Subject: [PATCH] support --mount type=bind,bind-nonrecursive,... Signed-off-by: Akihiro Suda --- cli/command/container/create.go | 4 ++++ cli/command/container/opts.go | 10 ++++++++++ cli/command/container/run.go | 4 ++++ cli/command/service/create.go | 4 ++++ cli/command/service/opts.go | 10 ++++++++++ opts/mount.go | 3 +++ 6 files changed, 35 insertions(+) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 62d1a088aa78..5a7805c3c020 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -65,6 +65,10 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *createOptions, reportError(dockerCli.Err(), "create", err.Error(), true) return cli.StatusError{StatusCode: 125} } + if err = validateAPIVersion(containerConfig, dockerCli.Client().ClientVersion()); err != nil { + reportError(dockerCli.Err(), "create", err.Error(), true) + return cli.StatusError{StatusCode: 125} + } response, err := createContainer(context.Background(), dockerCli, containerConfig, opts) if err != nil { return err diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 97906b672252..402e57c793d1 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -16,6 +16,7 @@ import ( "github.com/docker/docker/api/types/container" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/strslice" + "github.com/docker/docker/api/types/versions" "github.com/docker/docker/pkg/signal" "github.com/docker/go-connections/nat" "github.com/pkg/errors" @@ -866,3 +867,12 @@ func validateAttach(val string) (string, error) { } return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR") } + +func validateAPIVersion(c *containerConfig, serverAPIVersion string) error { + for _, m := range c.HostConfig.Mounts { + if m.BindOptions != nil && m.BindOptions.NonRecursive && versions.LessThan(serverAPIVersion, "1.40") { + return errors.Errorf("bind-nonrecursive requires API v1.40 or later") + } + } + return nil +} diff --git a/cli/command/container/run.go b/cli/command/container/run.go index d2ca58739f85..e1faadfd8e56 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -114,6 +114,10 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt reportError(dockerCli.Err(), "run", err.Error(), true) return cli.StatusError{StatusCode: 125} } + if err = validateAPIVersion(containerConfig, dockerCli.Client().ClientVersion()); err != nil { + reportError(dockerCli.Err(), "run", err.Error(), true) + return cli.StatusError{StatusCode: 125} + } return runContainer(dockerCli, ropts, copts, containerConfig) } diff --git a/cli/command/service/create.go b/cli/command/service/create.go index ec74eb43c3f6..c045682e0328 100644 --- a/cli/command/service/create.go +++ b/cli/command/service/create.go @@ -79,6 +79,10 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *serviceOptions return err } + if err = validateAPIVersion(service, dockerCli.Client().ClientVersion()); err != nil { + return err + } + specifiedSecrets := opts.secrets.Value() if len(specifiedSecrets) > 0 { // parse and validate secrets diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 834b53704876..2478ca8e89e8 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" + "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" "github.com/docker/swarmkit/api" "github.com/docker/swarmkit/api/defaults" @@ -909,3 +910,12 @@ const ( flagConfigRemove = "config-rm" flagIsolation = "isolation" ) + +func validateAPIVersion(c swarm.ServiceSpec, serverAPIVersion string) error { + for _, m := range c.TaskTemplate.ContainerSpec.Mounts { + if m.BindOptions != nil && m.BindOptions.NonRecursive && versions.LessThan(serverAPIVersion, "1.40") { + return errors.Errorf("bind-nonrecursive requires API v1.40 or later") + } + } + return nil +} diff --git a/opts/mount.go b/opts/mount.go index 3aa9849421ac..8b7082d5dbb0 100644 --- a/opts/mount.go +++ b/opts/mount.go @@ -76,6 +76,9 @@ func (m *MountOpt) Set(value string) error { case "volume-nocopy": volumeOptions().NoCopy = true continue + case "bind-nonrecursive": + bindOptions().NonRecursive = true + continue } }