---
title: "Does a Dockerfile root-user finding mean the container runs as root? | Proofline"
description: "It does when the final build stage sets no non-root USER and the deployment that runs the image does not override the user."
url: https://proofline.sh/learn/dockerfile-root-user-finding/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# Does a Dockerfile root-user finding mean the container runs as root?

It does when the final build stage sets no non-root USER and the deployment that runs the image does not override the user. A linter reads the Dockerfile, and checkov's checks read the whole file rather than the stage that becomes the image. Check the final stage yourself, then check every workload that runs the image.

Code review The Proofline team November 25, 2026 5 min read

## Two rules decide the user

The Dockerfile reference scopes `USER` to one stage: it sets the default user "for the remainder of the current stage", and "Each `FROM` instruction clears any state created by previous instructions." ([Dockerfile reference, BuildKit dockerfile/1.12.0](https://github.com/moby/buildkit/blob/dockerfile/1.12.0/frontend/dockerfile/docs/reference.md)) In a multi-stage build, the stage that becomes the image is the only one whose `USER` counts; for an ordinary build that is the last stage. The image records it in its configuration's `User` field, which the OCI image specification says "acts as a default value to use when the value is not specified when creating a container." ([Image configuration, image-spec v1.1.0](https://github.com/opencontainers/image-spec/blob/v1.1.0/config.md))

The runtime decides the rest. The Docker run reference states: "The default user within a container is `root` (uid = 0)", and it says the `-u` option overrides the `USER` instruction ([docker run reference, docker/cli v27.3.1](https://github.com/docker/cli/blob/v27.3.1/docs/reference/run.md)). Kubernetes documents `runAsUser` as "The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified." ([core/v1 types.go, kubernetes/api v0.31.2](https://github.com/kubernetes/api/blob/v0.31.2/core/v1/types.go))

So the evidence is the final stage, the built image's `User` field when you can inspect it, and the security settings of each workload. No Docker daemon was available for this guide, so the images below were not built; the reasoning about their user follows the Dockerfile rules quoted above.

## What checkov reports on five multi-stage files

These Dockerfiles are constructed. Each builds a Go binary in a `golang:1.24.7` stage and copies it into a `debian:12.7-slim` final stage. The first has no `USER` at all:

```
FROM golang:1.24.7 AS build
WORKDIR /src
COPY . .
RUN go build -o /out/api ./cmd/api

FROM debian:12.7-slim
COPY --from=build /out/api /usr/local/bin/api
HEALTHCHECK CMD ["/usr/local/bin/api", "-health"]
ENTRYPOINT ["/usr/local/bin/api"]
```

checkov 3.4.11, installed from PyPI, flags it:

```
$ checkov --skip-download --compact --framework dockerfile --check CKV_DOCKER_3,CKV_DOCKER_8 -f no-user/Dockerfile
Passed checks: 0, Failed checks: 1, Skipped checks: 0
Check: CKV_DOCKER_3: "Ensure that a user for the container has been created"
	FAILED for resource: no-user/Dockerfile.
```

The finding is right: the final stage sets no user, so the image runs as root by default. The other four files differ mainly in where `USER` appears. `builder-only` adds `RUN useradd --create-home builder` and `USER builder` to the build stage (building under `/home/builder`) and still sets no `USER` in the final stage. `final-user` adds `RUN useradd --uid 10001 --no-create-home app` and `USER 10001` to the final stage. `final-uid0` and `final-root` replace that last line with `USER 0` and `USER root`. The same command on each:

| Dockerfile | Final stage's user | CKV\_DOCKER\_3 | CKV\_DOCKER\_8 |
| --- | --- | --- | --- |
| `no-user` | root (no `USER`) | FAILED | not reported |
| `builder-only` | root (no `USER` in the final stage) | PASSED | PASSED |
| `final-user` | 10001 | PASSED | PASSED |
| `final-uid0` | root (UID 0) | PASSED | PASSED |
| `final-root` | root | PASSED | FAILED, at line 9 |

Two rows pass both checks while the image would run as root. The check sources at the same tag show why. `CKV_DOCKER_3` returns `CheckResult.PASSED` as soon as it finds any `USER` instruction in the file, in any stage ([UserExists.py, checkov 3.4.11](https://github.com/bridgecrewio/checkov/blob/3.4.11/checkov/dockerfile/checks/UserExists.py)). `CKV_DOCKER_8`, "Ensure the last USER is not root", takes the last `USER` in the file and fails only when its value is the string `root` ([RootUser.py, checkov 3.4.11](https://github.com/bridgecrewio/checkov/blob/3.4.11/checkov/dockerfile/checks/RootUser.py)), so `USER 0` passes.

This matters for the decision in both directions. A fix that adds `USER` to the build stage clears the finding and leaves the image unchanged, so review the fix by reading the final stage, not by rerunning the scan. And a clean scan of a multi-stage file is no evidence that the image runs as a non-root user.

## The disconfirmation: an override in one workload only

A common reason to dismiss the finding is that the deployment sets the user. That is true only for the workloads that set it. In this constructed example the `no-user` image, `registry.example.com/api:1.8.0`, runs in two places. The Deployment sets a pod security context:

```
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
      containers:
        - name: api
          image: registry.example.com/api:1.8.0
```

A nightly CronJob, added later for a reindex task, uses the same image with no security context:

```
          containers:
            - name: reindex
              image: registry.example.com/api:1.8.0
              args: ["-reindex"]
```

checkov's Kubernetes check sees the difference:

```
$ checkov --skip-download --compact --framework kubernetes --check CKV_K8S_23 -d k8s
Passed checks: 1, Failed checks: 1, Skipped checks: 0
Check: CKV_K8S_23: "Minimize the admission of root containers"
	PASSED for resource: Deployment.prod.api
	File: /k8s/api-prod.yaml:1-19
Check: CKV_K8S_23: "Minimize the admission of root containers"
	FAILED for resource: CronJob.prod.api-reindex
	File: /k8s/api-batch.yaml:1-16
```

No cluster was available here, so the manifests were scanned and not run. Under the documented defaults, the Deployment's container runs as UID 10001 and the CronJob's falls back to the image's user, which is root. The same field documentation says what `runAsNonRoot` does on its own: "If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does. If unset or false, no such validation will be performed." Set without `runAsUser`, it would stop the `no-user` image from starting, which surfaces the problem instead of fixing it.

To dismiss the Dockerfile finding on the strength of a runtime override, list every workload, script and `docker run` invocation that references the image, and confirm each one sets a non-root user. One that does not, like the CronJob here, makes the finding real.

## Decide from the final stage and each runtime

| What the finding says | Evidence to collect | Decision |
| --- | --- | --- |
| No `USER` in the Dockerfile | The final stage; the built image's configured user | Fix: add a non-root `USER` to the final stage |
| Scan passes, multi-stage file | Which stage holds the last `USER`, and its value (`0` counts as root) | Read the final stage; a pass from a build-stage `USER` is no evidence |
| Root image, deployment sets the user | Every workload and command that runs the image, and its `runAsUser` or `--user` | Dismiss only if every one sets a non-root user; otherwise fix the image |
| `runAsNonRoot: true` with a root image | Whether `runAsUser` is also set | Without `runAsUser` the container fails to start; fix the image |

The [container image review guide](/learn/container-image-review/) covers the other runtime properties to follow from build to deployment target. A runtime override that only some callers set is the same pattern as a module default that only some environments override, covered in the [guide to Terraform variable default findings](/learn/terraform-scan-variable-default/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Container image review](/learn/container-image-review/)
    
    Broken dependencies The Proofline team October 7, 2026 2 min read
    
-   ### [Is a checkov finding on a variable default real if every environment overrides it?](/learn/terraform-scan-variable-default/)
    
    Code review The Proofline team November 25, 2026 5 min read
