Checks / Docker and containers
A container runs as root
- Check
docker.root_user- Severity
- info
- Runs
- on the server, in the daily run of the agent
- Looks at
- Config.User is empty, 0 or root, the main process runs as UID 0, and user namespace remapping is off
What the check looks at
Config.User of every running container (docker inspect), the user of its main process, and whether the
daemon runs with user namespace remapping (userns-remap) or rootless. The check warns for a container when the
user is empty, 0 or root, its main process runs as UID 0, and remapping is off. Images such as redis and
postgres start as root and switch to their own user; their main process then runs as that user, and the check
does not report them. The severity is info: the list is for you to decide on.
Risk
Without remapping, root in a container is UID 0 on the host, with fewer capabilities. An attacker who gets code execution in the application controls every file of the image, all mounted secrets and volumes, and the 14 default capabilities, and a kernel or container runtime bug that allows an escape makes them root on the host. An unprivileged user takes that head start away.
How to fix it
For images you build, add a user with a fixed UID and switch to it:
# Debian or Ubuntu base
RUN groupadd --gid 10001 app \
&& useradd --uid 10001 --gid app --no-create-home --shell /usr/sbin/nologin app
USER 10001:10001
# Alpine base
RUN addgroup -S -g 10001 app \
&& adduser -S -D -H -u 10001 -G app -s /sbin/nologin app
USER 10001:10001
Distroless images have a nonroot tag (UID 65532); the official node images have the user node.
For images you do not build, set the user at run time and give it the volumes it writes to:
services:
app:
image: example/app:1.4.2
user: "10001:10001"
sudo chown -R 10001:10001 /srv/app-data
docker compose up -d --force-recreate app
For the whole host, "userns-remap": "default" in /etc/docker/daemon.json maps root in every container to an
unprivileged range on the host. Existing images and containers are not visible after the switch, so plan it for
a new host or a maintenance window.
How to check the fix
docker ps -q | xargs -r docker inspect --format '{{.Name}} user={{.Config.User}}'
docker top <container> -o user,pid,comm
The first command shows the configured user, the second the user the processes run as.
When a warning is fine
Containers that manage the host need root, such as a backup agent that must read all files; accept the result
for them on the dashboard. In a test, the official redis:8.10.2-alpine3.23 and postgres:17.11-alpine3.24
images had an empty Config.User, and docker top showed their server processes as UID 999 and 70. If such an
image is reported anyway and docker top shows that the main program does not run as root, accept the result.
An accepted result stays out of the digest and the counts until it changes.
Sources
- Docker docs: Running containers, User ("The default user
within a container is
root(uid = 0).") - Docker docs: Dockerfile reference, USER
- Docker docs: Isolate containers with a user namespace