Merge pull request #25701 from WeiZhang555/update-conflict-rm-restart
Forbid update restart policy of container with AutoRemove flag
This commit is contained in:
commit
9a3e7d9e34
7 changed files with 28 additions and 4 deletions
|
@ -95,6 +95,9 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
|
|||
return cli.StatusError{StatusCode: 125}
|
||||
}
|
||||
|
||||
if hostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
|
||||
return ErrConflictRestartPolicyAndAutoRemove
|
||||
}
|
||||
if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 {
|
||||
fmt.Fprintf(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.\n")
|
||||
}
|
||||
|
@ -166,9 +169,6 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
|
|||
fmt.Fprintf(stdout, "%s\n", createResponse.ID)
|
||||
}()
|
||||
}
|
||||
if hostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
|
||||
return ErrConflictRestartPolicyAndAutoRemove
|
||||
}
|
||||
attach := config.AttachStdin || config.AttachStdout || config.AttachStderr
|
||||
if attach {
|
||||
var (
|
||||
|
|
|
@ -302,6 +302,9 @@ func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfi
|
|||
|
||||
// update HostConfig of container
|
||||
if hostConfig.RestartPolicy.Name != "" {
|
||||
if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
|
||||
return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
|
||||
}
|
||||
container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,9 @@ func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfi
|
|||
}
|
||||
// update HostConfig of container
|
||||
if hostConfig.RestartPolicy.Name != "" {
|
||||
if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
|
||||
return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
|
||||
}
|
||||
container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -460,7 +460,7 @@ Create a container
|
|||
An ever increasing delay (double the previous delay, starting at 100mS)
|
||||
is added before each restart to prevent flooding the server.
|
||||
- **AutoRemove** - Boolean value, set to `true` to automatically remove the container on daemon side
|
||||
when the container's process exits.
|
||||
when the container's process exits. Note that `RestartPolicy` other than `none` is exclusive to `AutoRemove`.
|
||||
- **UsernsMode** - Sets the usernamespace mode for the container when usernamespace remapping option is enabled.
|
||||
supported values are: `host`.
|
||||
- **NetworkMode** - Sets the networking mode for the container. Supported
|
||||
|
|
|
@ -107,3 +107,7 @@ To update restart policy for one or more containers:
|
|||
```bash
|
||||
$ docker update --restart=on-failure:3 abebf7571666 hopeful_morse
|
||||
```
|
||||
|
||||
Note that if the container is started with "--rm" flag, you cannot update the restart
|
||||
policy for it. The `AutoRemove` and `RestartPolicy` are mutually exclusive for the
|
||||
container.
|
||||
|
|
|
@ -29,3 +29,13 @@ func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) {
|
|||
maximumRetryCount := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount")
|
||||
c.Assert(maximumRetryCount, checker.Equals, "5")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestUpdateRestartWithAutoRemoveFlag(c *check.C) {
|
||||
out, _ := runSleepingContainer(c, "--rm")
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
// update restart policy for an AutoRemove container
|
||||
out, _, err := dockerCmdWithError("update", "--restart=always", id)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(out, checker.Contains, "Restart policy cannot be updated because AutoRemove is enabled for the container")
|
||||
}
|
||||
|
|
|
@ -148,3 +148,7 @@ To update restart policy for one or more containers:
|
|||
```bash
|
||||
$ docker update --restart=on-failure:3 abebf7571666 hopeful_morse
|
||||
```
|
||||
|
||||
Note that if the container is started with "--rm" flag, you cannot update the restart
|
||||
policy for it. The `AutoRemove` and `RestartPolicy` are mutually exclusive for the
|
||||
container.
|
||||
|
|
Loading…
Reference in a new issue