Dockerfile USER: run with a nonroot identity
Read the recipe
FROM busybox:1.37RUN mkdir /app && chown 10001:10001 /appUSER 10001:10001WORKDIR /appRUN printf "prepared\n" > note.txtCMD ["sh", "-c", "id -u; id -g; cat note.txt"]The first RUN assumes the reviewed base defaults to root; it prepares /app for UID and GID 10001. The following RUN writes as that identity. The runtime command displays numeric identifiers and the file. Numeric IDs do not automatically create account names. An application needing a home directory or name lookup may require an explicitly created account. The example does not require a host mount. The explicit numeric group matters as well as the UID. File ownership alone does not ensure access: directory traversal and mode also matter. USER can be overridden at container creation by an authorized operator.
Try it in a local lab
Manual lab only, not an interactive ByteMind execution. Use an approved disposable offline Linux VM, verified local Engine and Buildx docker driver. Check docker context show, docker version, docker buildx version and docker buildx ls. Confirm the local context/builder, reviewed preloaded busybox:1.37 with root default, no entrypoint, and required applets. Record actual digest/platform and use reviewed digest for repeatability. No network egress; --network none is not a complete builder egress control. Verify every bm-v08 image tag and container name in the commands is unused. Use synthetic data only. Run commands individually and stop on unexpected failure; remove only resources created by this lab after ownership checks. If cleanup cannot be confirmed, retire the disposable VM. Expected results are predictions, not observed output. Before contacting any Engine, resolve DOCKER_HOST, DOCKER_CONTEXT and CLI context overrides; also check BUILDX_BUILDER and any builder override. Confirm that the actual builder used by docker build is the approved local docker driver. Review the base configuration for inherited triggers, volumes, health checks, user, shell and required applets; stop if assumptions differ. Make a private working copy containing only the supplied synthetic files. An approved digest may require registry metadata resolution even when layers are present locally; if the offline builder cannot resolve it, stop and record the limitation. Record the actual base image ID, platform, builder version and output image ID; never substitute an unknown digest. Do not retry by enabling egress. Apply owner-approved time and resource budgets and retire the VM if cleanup is uncertain.
Open lab-fixtures/dockerfile-configuration/03-user/ from the extracted archive. Save the complete recipe and any additional files below in that directory.
docker build --load --network none -t bm-v08-user:lab .docker run --rm --pull=never --network none bm-v08-user:labdocker image inspect --format '{{.Config.User}}' bm-v08-user:labExpect 10001, 10001 and prepared on separate lines; inspect should show 10001:10001. This is an intended identity check, not a security audit.
Confirm the tag belongs to this lab and no container depends on it. Remove it without forcing deletion. Build cache may remain until VM disposal. Record output and exit status before removing the exact lab tag. Recheck the tag against the recorded output image ID; a tag may have been reassigned.
Common mistake
USER does not fix directory ownership and does not make a container rootless at the engine level. Prepare only the application paths that need writes. Do not grant everyone write permission as a shortcut.
Manual practice
Predict what could happen if chown is removed from this recipe. Explain why changing the runtime user alone cannot grant access to a directory owned by root.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dockerfile USER: run with a nonroot identity — Knowledge check
Apply the configuration concept to a new image or container scenario.
Which command runs as UID 10001?
What does chown prepare?
Does USER establish rootless Docker Engine?