Skip to content

Hardening a container: user, read-only root, capabilities

Select an icon to see what it is.

Step 3 of 6

--read-only freezes the root filesystem

--read-only sets HostConfig.ReadonlyRootfs, and the overlay root is mounted read-only. Any write outside a mount fails with a read-only file system error. --tmpfs /tmp adds a writable, memory-backed directory for the files a program really needs.

$ docker run -d --name hardened --user 1000:1000 --read-only --tmpfs /tmp alpine sleep 1000

HostConfig in the create request

{
"HostConfig": {
"ReadonlyRootfs": true
"Tmpfs": {
"/tmp": ""
}
}
}