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 or 0 and user namespace remapping is off
What the check looks at
The agent reads Config.User of every running container from docker inspect, and whether the daemon runs
with user namespace remapping (userns-remap). It reports a container when the user is empty, 0 or
root and remapping is off. The status is informational: it lists the containers so you can decide.
Why it matters
Without remapping, root in a container is UID 0 on the host, with fewer capabilities. An attacker who gets code execution in the application starts with full control of the container: they can change every file of the image, read all mounted secrets and volumes, and use the 14 default capabilities. Any escape through a kernel or container runtime bug then lands them as root on the host. An unprivileged user removes that head start.
How to fix it
The steps are the same on every distribution; only the commands inside the Dockerfile depend on the base image.
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
As an alternative 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 UID the processes run as.
When a warning is fine
Many images start as root and switch to an unprivileged user in their entrypoint. In a test, the official
redis:8.10.2-alpine3.23 and postgres:17.11-alpine3.24 images had an empty Config.User, but
docker top showed their server processes as UID 999 and 70. If docker top does not show a root process for
the main program, the finding is harmless. Containers that manage the host, such as a backup agent that must read
all files, also need root; accept the result for such a container on the dashboard.
An accepted result is left out of the digest and the counts until it changes; then it shows again.
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