Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReadonlyRootfs option to the Docker driver #3802

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ type DockerDriverConfig struct {
Devices []DockerDevice `mapstructure:"devices"` // To allow mounting USB or other serial control devices
CapAdd []string `mapstructure:"cap_add"` // Flags to pass directly to cap-add
CapDrop []string `mapstructure:"cap_drop"` // Flags to pass directly to cap-drop
ReadonlyRootfs bool `mapstructure:"readonly_rootfs"` // Mount the container’s root filesystem as read only
}

func sliceMergeUlimit(ulimitsRaw map[string]string) ([]docker.ULimit, error) {
Expand Down Expand Up @@ -670,6 +671,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
"cap_drop": {
Type: fields.TypeArray,
},
"readonly_rootfs": {
Type: fields.TypeBool,
},
},
}

Expand Down Expand Up @@ -1243,6 +1247,7 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas
hostConfig.SecurityOpt = driverConfig.SecurityOpt
hostConfig.Sysctls = driverConfig.Sysctl
hostConfig.Ulimits = driverConfig.Ulimit
hostConfig.ReadonlyRootfs = driverConfig.ReadonlyRootfs

hostConfig.NetworkMode = driverConfig.NetworkMode
if hostConfig.NetworkMode == "" {
Expand Down
22 changes: 22 additions & 0 deletions client/driver/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2247,3 +2247,25 @@ func TestDockerDriver_Kill(t *testing.T) {
err = handle.Kill()
assert.Nil(err)
}

func TestDockerDriver_ReadonlyRootfs(t *testing.T) {
if !tu.IsTravis() {
t.Parallel()
}
if !testutil.DockerIsConnected(t) {
t.Skip("Docker not connected")
}

task, _, _ := dockerTask(t)
task.Config["readonly_rootfs"] = true

client, handle, cleanup := dockerSetup(t, task)
defer cleanup()

waitForExist(t, client, handle)

container, err := client.InspectContainer(handle.ContainerID())
assert.Nil(t, err, "Error inspecting container: %v", err)

assert.True(t, container.HostConfig.ReadonlyRootfs, "ReadonlyRootfs option not set")
}
3 changes: 3 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ The `docker` driver supports the following configuration in the job spec. Only
}
```

* `readonly_rootfs` - (Optional) `true` or `false` (default). Mount
the container's filesystem as read only.

### Container Name

Nomad creates a container after pulling an image. Containers are named
Expand Down