Skip to content

Commit

Permalink
Resolve conflicts with restart policies
Browse files Browse the repository at this point in the history
Signed-off-by: Tibor Vass <teabee89@gmail.com>
  • Loading branch information
tiborvass committed Sep 16, 2014
1 parent 22eb3a3 commit e49c701
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
15 changes: 10 additions & 5 deletions api/client/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 6 additions & 12 deletions runconfig/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")

This comment has been minimized.

Copy link
@thockin

thockin Sep 29, 2014

Contributor

I just ran across this change. I do not understand why this is necessarily a conflict? Network and UTS are different namespaces. I see no reason why different containers can not have different names for the same IP, or different /etc/hosts contents, or different DNS resolvers.

Is there a reason for it? Fortunately we are not broken by it because we set hostname the same already (we set the field through the API without error), but it was surprising to at least one of our users.

This comment has been minimized.

Copy link
@aluzzardi

aluzzardi May 4, 2015

Member

Just ran across this change as well and I don't understand why.

@tiborvass ?

This comment has been minimized.

Copy link
@tiborvass

tiborvass May 4, 2015

Author Contributor

This comment has been minimized.

Copy link
@ketzacoatl

ketzacoatl Apr 13, 2016

I just ran across this limitation, it is arbitrary and completely non-sensicle. In my use of docker, this means I need to force all containers on the host to have the same DNS, just so some of my containers can use --net=host networking mode. As a user, this is a bit infuriating.

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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e49c701

Please sign in to comment.