Skip to content

Docker audit fix · Image Vulnerabilities

How to Check and Configure Default Docker Image Users

An image that declares no USER runs as root by default, so any process that escapes the application owns uid 0 inside the container. Add a numeric non-root USER at the end of the Dockerfile, after the installs and the chowns.

Hiren KalariyaHiren KalariyaLast reviewed image-configuration-review
CtrlOpsImage Default UserMEDIUM

What did your audit say?

WARN · when the audit printed

Some images have no USER

At least one sampled image would run as root unless the run command overrides it, and the message names up to five.

Severity
Medium
Needs root or sudo
Yes
Results it can return
WARN · SKIP · PASS
Check in this audit
4 of 8

Every threshold on this page is transcribed from the docker-security-image-vulnerabilities audit script that CtrlOps runs, and a build check fails if the two ever disagree. See all 8 Image Vulnerabilities checks, or how the audit runs.

The check takes the first 10 tagged local images from docker images --format '{{.Repository}}:{{.Tag}}', <none> entries excluded, and reads docker inspect -f '{{.Config.User}}' <img> for each of them. Three values count as root: an empty string, the literal root, and 0. If none of the sampled images fall into that group the check PASSes; if any do it WARNs and names at most 5 of them, and an empty image list is the SKIP.

Needs the docker binary and daemon access; otherwise SKIP. It inspects the first 10 tagged local images and reads .Config.User from each - the USER declared in the image, with empty, root and 0 all counting as root. This is about images, not running containers: an image with no USER that is always run with -u 1000 still produces a finding, and conversely an image with a USER can be overridden at run time. The running-container equivalent is the Container User check. Despite the check's name, only the default user is reviewed - exposed ports, healthchecks and other image configuration are not examined here.

What each result means
ResultWhenWhat it means
SKIPDocker not installed, daemon unreachable, or no local imagesNothing was inspected. No image list was produced, so the check says nothing about the default user of anything on this host.
PASSEvery image sets a non-root USEREvery image in the sample declares a USER that is neither root nor 0. A run-time --user override can still change what the container actually runs as.
WARNSome images have no USERAt least one sampled image would run as root unless the run command overrides it, and the message names up to five.

Same principle as Container User but at the image level: CIS Docker 4.1 "Ensure that a user for the container has been created"; Dockerfile USER; Dockle CIS-DI-0001. Images without USER run as root unless overridden at run time.

  • Official images (nginx, postgres, redis, mysql, mongo, node, python) ship without USER on purpose (entrypoint drops privileges, or they leave it to the operator). This WARN is informational for those; the Container User check on the running container is the one that matters.
  • Images pulled only as build stages or caches are included in the sample.
  • Sample is 10 images, in docker images order (newest first).
  • Only the exact values root and 0 count, alongside an empty one. USER 0:0 and USER root:root name a group as well, match neither string, and pass as non-root. The Container User check does treat those forms as root on the running container.
  1. Create the account and hand it its files

    Do this after the package installs, which still need root.

    dockerfile
    RUN groupadd -r -g 10001 app && useradd -r -u 10001 -g app app \ && chown -R 10001:10001 /app

    That is the Debian, Ubuntu and RHEL form. On Alpine use addgroup -S -g 10001 app && adduser -S -u 10001 -G app app.

  2. Switch with a numeric USER

    dockerfile
    USER 10001:10001

    Put it after every instruction that needs root and before CMD. A numeric ID does not depend on an /etc/passwd lookup at run time.

  3. Rebuild and confirm

    sh
    docker build -t app:1.4.3 .docker run --rm app:1.4.3 id# expected: uid=10001, not uid=0(root)

  4. For images you do not build

    You cannot change someone else's image. Use its non-root variant where one exists, derive your own image that adds a USER line, or set the user at run time with --user or Compose user:, and record the base-image finding as accepted.

sh
docker images --format '{{.Repository}}:{{.Tag}}' | grep -v '<none>' | \  xargs -I{} sh -c 'printf "%s user=%s\n" {} "$(docker image inspect -f "{{.Config.User}}" {})"'# expected: a non-root user or UID for every image# Confirm a rebuilt image really runs as that user:docker run --rm <image> id# expected: uid=10001 (or whatever you set), not uid=0(root)

Debugging

  • Three different cases share this status. 'Docker not installed' is correct on a host with no Docker. 'Cannot query Docker daemon' means the audit account could not reach the daemon: check systemctl is-active docker, then docker ps as that user and sudo docker ps, and run the audit as root or with sudo if only the second works. 'No local images found' means the daemon held no tagged images, which is normal on a host that pulls at deploy time; check with docker images -a. It is also what you get when the audit has root but the daemon is down, because an empty answer and an empty image list look the same to the script. The Docker Inventory check covers the unreachable case in more detail.
  • Most official images (nginx, postgres, node) ship without a USER by design and expect you to set it at run time, or drop privileges in their entrypoint. You cannot fix someone else's image; set the user when you run it (--user, Compose user:) or in your own derived image, and record the base-image finding as accepted.
  • The image's USER can be overridden at run time. Cross-check with the Container User check and docker inspect -f '{{.Config.User}}' $(docker ps -q).
  • The instruction applies to everything after it, so package installs and chowns must come first. Create the account explicitly and give it ownership: RUN useradd -u 10001 -r app && chown -R 10001 /app, then USER 10001. Prefer a numeric UID so the runtime does not depend on /etc/passwd lookups.
  • The sample is capped at 10 images and the message lists at most 5. Use the command above for the complete picture.

Sources

Next

Re-run the Image Vulnerabilities audit after applying the fix and confirm this check moves to PASS. CtrlOps runs all 8 checks over your existing SSH connection and scores the result, so the change is visible without reading another config file.

Download for MacDownload for WindowsAll 8 Image Vulnerabilities fixes

14-day free trial, no credit card required.

Explore article with AI tools

Written by

Hiren Kalariya

Co-Founder & CEO, TST Technology

Hiren Kalariya is the Co-Founder and CEO of TST Technology and the product lead behind CtrlOps, a local-first desktop app that makes Linux server management fast and easy for developers and DevOps teams. Over the past five years he has shipped 60+ production systems, and he still tests every tool he writes about on real servers.

Stop juggling tools. Start managing fleets.

PuTTY
Termius
MobaXterm
WinSCP
SecureCRT
Royal TS
Warp
CtrlOps14 tools left
Webmin
aaPanel
RunCloud
Dokploy
IP spreadsheet
bash (2)
sticky notes

One app. All your servers. No context switching. Free to start, free to leave.

Start instantly · No credit card · Cancel anytime

Your privacy preferences. We use product analytics to improve CtrlOps. Google Analytics cookies and live chat stay off until you allow them. Cookie policy