Skip to content

Commit

Permalink
docker: configure restart policy for networking pause container (#15732)
Browse files Browse the repository at this point in the history
This PR modifies the configuration of the networking pause contaier to include
the "unless-stopped" restart policy. The pause container should always be
restored into a running state until Nomad itself issues a stop command for the
container.

This is not a _perfect_ fix for #12216 but it should cover the 99% use case -
where a pause container gets accidently stopped / killed for some reason. There
is still a possibility where the pause container and main task container are
stopped and started in the order where the bad behavior persists, but this is
fundamentally unavoidable due to how docker itself abstracts and manages the
underlying network namespace referenced by the containers.

Closes #12216
  • Loading branch information
shoenig authored and philrenaud committed Jan 23, 2023
1 parent c54e63e commit b59c96e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/15732.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
docker: configure restart policy for bridge network pause container
```
6 changes: 6 additions & 0 deletions drivers/docker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ func (d *Driver) createSandboxContainerConfig(allocID string, createSpec *driver
// Set the network mode to none which creates a network namespace
// with only a loopback interface.
NetworkMode: "none",

// Set the restart policy to unless-stopped. The pause container should
// never not be running until Nomad issues a stop.
//
// https://docs.docker.com/engine/reference/run/#restart-policies---restart
RestartPolicy: docker.RestartUnlessStopped(),
},
}, nil
}
Expand Down
6 changes: 4 additions & 2 deletions drivers/docker/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func TestDriver_createSandboxContainerConfig(t *testing.T) {
Image: "gcr.io/google_containers/pause-amd64:3.1",
},
HostConfig: &docker.HostConfig{
NetworkMode: "none",
NetworkMode: "none",
RestartPolicy: docker.RestartUnlessStopped(),
},
},
name: "no input hostname",
Expand All @@ -45,7 +46,8 @@ func TestDriver_createSandboxContainerConfig(t *testing.T) {
Hostname: "linux",
},
HostConfig: &docker.HostConfig{
NetworkMode: "none",
NetworkMode: "none",
RestartPolicy: docker.RestartUnlessStopped(),
},
},
name: "supplied input hostname",
Expand Down

0 comments on commit b59c96e

Please sign in to comment.