diff --git a/api/client/commands.go b/api/client/commands.go index e03aeb2af4..585ee0066e 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -2099,10 +2099,11 @@ func (cli *DockerCli) CmdRun(args ...string) error { flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run the container in the background and print the new container ID") flSigProxy = cmd.Bool([]string{"#sig-proxy", "-sig-proxy"}, true, "Proxy received signals to the process (even in non-TTY mode). SIGCHLD, SIGSTOP, and SIGKILL are not proxied.") flName = cmd.String([]string{"#name", "-name"}, "", "Assign a name to the container") + flAttach *opts.ListOpts - flAttach *opts.ListOpts - - ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d") + ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d") + ErrConflictRestartPolicyAndAutoRemove = fmt.Errorf("Conflicting options: --restart and --rm") + ErrConflictDetachAutoRemove = fmt.Errorf("Conflicting options: --rm and -d") ) config, hostConfig, cmd, err := runconfig.ParseSubcommand(cmd, args, nil) @@ -2118,11 +2119,11 @@ func (cli *DockerCli) CmdRun(args ...string) error { if fl := cmd.Lookup("attach"); fl != nil { flAttach = fl.Value.(*opts.ListOpts) if flAttach.Len() != 0 { - return fmt.Errorf("Conflicting options: -a and -d") + return ErrConflictAttachDetach } } if *flAutoRemove { - return fmt.Errorf("Conflicting options: --rm and -d") + return ErrConflictDetachAutoRemove } config.AttachStdin = false @@ -2161,6 +2162,10 @@ func (cli *DockerCli) CmdRun(args ...string) error { }() } + if *flAutoRemove && (hostConfig.RestartPolicy.Name == "always" || hostConfig.RestartPolicy.Name == "on-failure") { + return ErrConflictRestartPolicyAndAutoRemove + } + // We need to instanciate the chan because the select needs it. It can // be closed but can't be uninitialized. hijacked := make(chan io.Closer) diff --git a/runconfig/parse.go b/runconfig/parse.go index 419e7d4dcf..d3b165dd95 100644 --- a/runconfig/parse.go +++ b/runconfig/parse.go @@ -17,14 +17,12 @@ import ( ) var ( - ErrInvalidWorkingDirectory = fmt.Errorf("The working directory is invalid. It needs to be an absolute path.") - ErrConflictContainerNetworkAndLinks = fmt.Errorf("Conflicting options: --net=container can't be used with links. This would result in undefined behavior.") - ErrConflictContainerNetworkAndDns = fmt.Errorf("Conflicting options: --net=container can't be used with --dns. This configuration is invalid.") - ErrConflictDetachAutoRemove = fmt.Errorf("Conflicting options: --rm and -d") - ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: -h and the network mode (--net)") - ErrConflictHostNetworkAndDns = fmt.Errorf("Conflicting options: --net=host can't be used with --dns. This configuration is invalid.") - ErrConflictHostNetworkAndLinks = fmt.Errorf("Conflicting options: --net=host can't be used with links. This would result in undefined behavior.") - ErrConflictRestartPolicyAndAutoRemove = fmt.Errorf("Conflicting options: --restart and --rm") + ErrInvalidWorkingDirectory = fmt.Errorf("The working directory is invalid. It needs to be an absolute path.") + ErrConflictContainerNetworkAndLinks = fmt.Errorf("Conflicting options: --net=container can't be used with links. This would result in undefined behavior.") + ErrConflictContainerNetworkAndDns = fmt.Errorf("Conflicting options: --net=container can't be used with --dns. This configuration is invalid.") + ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: -h and the network mode (--net)") + ErrConflictHostNetworkAndDns = fmt.Errorf("Conflicting options: --net=host can't be used with --dns. This configuration is invalid.") + ErrConflictHostNetworkAndLinks = fmt.Errorf("Conflicting options: --net=host can't be used with links. This would result in undefined behavior.") ) // FIXME Only used in tests @@ -247,10 +245,6 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf return nil, nil, cmd, err } - if *flAutoRemove && (restartPolicy.Name == "always" || restartPolicy.Name == "on-failure") { - return nil, nil, cmd, ErrConflictRestartPolicyAndAutoRemove - } - config := &Config{ Hostname: hostname, Domainname: domainname,