1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #36924 from runcom/fix-created-rp

restartmanager: do not apply restart policy on created containers
This commit is contained in:
Sebastiaan van Stijn 2018-04-25 21:48:01 +02:00 committed by GitHub
commit 18bfe3c128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -320,7 +320,7 @@ func (daemon *Daemon) restore() error {
// not initialized yet. We will start
// it after the cluster is
// initialized.
if daemon.configStore.AutoRestart && c.ShouldRestart() && !c.NetworkSettings.HasSwarmEndpoint {
if daemon.configStore.AutoRestart && c.ShouldRestart() && !c.NetworkSettings.HasSwarmEndpoint && c.HasBeenStartedBefore {
mapLock.Lock()
restartContainers[c] = make(chan struct{})
mapLock.Unlock()
@ -450,7 +450,7 @@ func (daemon *Daemon) RestartSwarmContainers() {
// Autostart all the containers which has a
// swarm endpoint now that the cluster is
// initialized.
if daemon.configStore.AutoRestart && c.ShouldRestart() && c.NetworkSettings.HasSwarmEndpoint {
if daemon.configStore.AutoRestart && c.ShouldRestart() && c.NetworkSettings.HasSwarmEndpoint && c.HasBeenStartedBefore {
group.Add(1)
go func(c *container.Container) {
defer group.Done()

View file

@ -22,6 +22,7 @@ func TestDaemonRestartKillContainers(t *testing.T) {
xRunning bool
xRunningLiveRestore bool
xStart bool
}
for _, c := range []testCase{
@ -29,6 +30,7 @@ func TestDaemonRestartKillContainers(t *testing.T) {
desc: "container without restart policy",
config: &container.Config{Image: "busybox", Cmd: []string{"top"}},
xRunningLiveRestore: true,
xStart: true,
},
{
desc: "container with restart=always",
@ -36,6 +38,12 @@ func TestDaemonRestartKillContainers(t *testing.T) {
hostConfig: &container.HostConfig{RestartPolicy: container.RestartPolicy{Name: "always"}},
xRunning: true,
xRunningLiveRestore: true,
xStart: true,
},
{
desc: "container created should not be restarted",
config: &container.Config{Image: "busybox", Cmd: []string{"top"}},
hostConfig: &container.HostConfig{RestartPolicy: container.RestartPolicy{Name: "always"}},
},
} {
for _, liveRestoreEnabled := range []bool{false, true} {
@ -72,8 +80,10 @@ func TestDaemonRestartKillContainers(t *testing.T) {
assert.NilError(t, err)
defer client.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
assert.NilError(t, err)
if c.xStart {
err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
assert.NilError(t, err)
}
stopDaemon(t, d)
d.Start(t, args...)