Understanding the Docker USER Instruction
Docker containers run as root (UID 0) unless a Dockerfile sets the USER instruction, which widens the damage if a container is compromised. Recommended practices: always set USER explicitly, prefer numeric UID:GID over names, and create a dedicated application user with useradd. Switch to root only for privileged build steps such as package installs, and pair USER with WORKDIR and chown so the user can write to its directories and mounted volumes. A side-by-side Dockerfile demo shows the default root user versus a custom UID/GID 1234 user, and user namespaces (used by Docker's Enhanced Container Isolation) can map in-container root to an unprivileged host ID.
Related posts
- Kubernetes v1.37: KubeletInUserNamespace (aka Rootless mode) Graduates to Beta
Kubernetes Blog mediumAdeptKubernetes v1.37 promotes the KubeletInUserNamespace feature gate to beta, enabling all node components (kubelet, CRI/OCI runtimes, CNI plugins, kube-proxy) to run as a non-root host user inside a Linux user namespace so container-breakout bugs like runc and containerd CVEs are confined to that account. The gate itself mainly makes the kubelet tolerate permission errors on certain sysctls and /dev/kmsg. The user namespace must be created externally, for example via rootless Docker. Beta enables the gate by default with no effect on rootful clusters, exposes a runningInUserNamespace node property for labeling or tainting, and adds rootless conformance CI. Combined with hostUsers: false pods, it allows Kubernetes-in-Kubernetes without privileged containers, usable today via kind, minikube, Usernetes or k3s.
- Zero Trust and Docker Desktop: An Introduction
Docker easyNoviceZero Trust principles from NIST SP 800-207 can be applied to Docker Desktop development environments through host hardening, least privilege, network microsegmentation, strong authentication, monitoring and immutability. Enhanced Container Isolation (ECI) in Hardened Docker Desktop runs even --privileged containers unprivileged, remaps container root via user namespaces, blocks sensitive syscalls and restricts Docker Engine API access. Further controls include bridge/Macvlan networks and air-gapped containers for segmentation, SSO/SCIM plus Registry and Image Access Management for authorization, Docker Scout SBOM-based policy checks, and --read-only root filesystems paired with selective read/write volumes.
- Docker Best Practices: Understanding the Differences Between ADD and COPY Instructions in Dockerfiles
Docker mediumAdeptDockerfile COPY only copies files and directories from the build context into an image layer. ADD can do the same, but it also downloads URLs and automatically extracts local and remote archives. That extra behaviour brings flexibility, but also unpredictability and security risk from external content, so COPY is the sensible default and ADD should be reserved for cases that need fetching or extraction. Both instructions also work with remote build contexts such as Git repositories, remote tarball URLs and OCI images, with COPY still scoped to the context.
- Server-side sandboxing: Containers and seccomp
Figma mediumAdept
Containers and seccomp offer lighter-weight sandboxing than VMs, but both shift much more configuration responsibility onto the user. Container escape risk depends on the runtime implementation, kernel primitives and configuration, and a sandboxed container still needs network, credential and data isolation to limit damage if compromised. Seccomp-only sandboxes suit pure-compute programs: Figma allows only writing to already-open file descriptors, exiting, memory allocation and fetching the time. Building allowlists with strace, restructuring programs so risky syscalls happen before untrusted input is processed, and maintaining brittle allowlists are the main costs, in exchange for very low overhead.
- Coding Agent Horror Stories: The rm -rf ~/ Incident
Docker mediumAdeptAn AI coding agent asked to clean up an old repo ran `rm -rf tests/ patches/ plan/ ~/`, and the trailing `~/` expanded to the user's home directory and wiped an entire Mac, including the Keychain, SSH keys and years of files, with TRIM-enabled SSDs ruling out recovery. The same pattern appears in Claude Code GitHub issues #10077 and #12637 and in a Claude Cowork incident that deleted 15 years of family photos. The root cause is architectural: the agent runs as the user with inherited shell permissions, and nothing sits between the model's command and its execution. Docker argues that running agents in Docker Sandboxes (microVMs managed via the `sbx` CLI) contains this failure class through workspace-scoped mounts, default-blocked credential paths and read-only mounts.