USER
The Dockerfile instruction that sets which user later instructions and the container run as.
In more detail
Without it containers run as root. Create an unprivileged user in the image and switch to it with USER app (or a numeric UID such as 10001) near the end, after steps that need root. It is one of the cheapest and most effective hardening steps.
Examples
RUN adduser -D -u 10001 app
USER 10001USER node before CMD in the runner stageUSER nonroot:nonrootUSER 10001Related terms
- non-root user — An ordinary user account with limited rights, which a container should run its service as.
- root user — The all-powerful administrator account on Linux, with user ID 0, which can read or change anything.
- UID and GID — The numbers Linux uses to identify a user (UID) and a group (GID); root is UID 0.
- file permissions — Rules on each file saying which user and group own it and who may read, write or run it.
- Dockerfile — A text file of instructions, such as FROM, COPY and RUN, that tells Docker how to build an image.
Taught in
- Container Images The Exam Way — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Design And Build: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Mock Exam: Sixteen Tasks Against The Clock — Certified Kubernetes Application Developer (CKAD) Exam Prep
- The Host Footprint: Six Doors On A Worker — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Minimal Base Images: Less To Attack — Certified Kubernetes Security Specialist (CKS) Exam Prep
- An Image That Runs As Root: Security Best Practices — CompTIA Cloud+ (CV0-004) Exam Prep
- Container Hardening: Distroless & Rootless — Cloud Security & DevSecOps Engineering
- Install Docker And Verify Your Environment — Docker Architecture & Production Containers
- CMD, ENTRYPOINT, USER And Process Signals — Docker Architecture & Production Containers
- Minimal Bases, Non Root Users And Smaller Images — Docker Architecture & Production Containers
- Ephemeral Filesystems And Named Volumes — Docker Architecture & Production Containers
- Containerization Architecture: Multi-Stage Dockerfiles — Production Full-Stack Engineering
- Shipping in Scratch and Distroless Images — Concurrent Systems Programming with Go
- Packaging Into A Container — Modern Java: Virtual Threads & High-Throughput Services
- Pin It, Lint It, Prove It: Images And Runtimes — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Container Security: Minimal Bases And Non Root — Application Security & Threat Modeling for Engineers
- Twelve Lines, Ten Warnings: Dockerfile Instructions And hadolint — Docker Certified Associate (DCA) Exam Prep
- One Edited File, Six Rebuilt Steps: Layers, Cache And Flat Images — Docker Certified Associate (DCA) Exam Prep
- Root, But Not That Root: Default Engine Security And Image Scanning — Docker Certified Associate (DCA) Exam Prep
- Security Sprint: Eight Questions On Defaults, Trust And Access — Docker Certified Associate (DCA) Exam Prep
- Works On My Laptop: Images, Containers, Volumes And Networks — CompTIA Linux+ (XK0-006) Exam Prep
References
- Dockerfile reference: USER
- Dockerfile best practices
- Dockerfile reference
- OWASP Docker Security Cheat Sheet
Certification courses
- CKAD course and practice exam: Certified Kubernetes Application Developer
- CKS course and practice exam: Certified Kubernetes Security Specialist
- CompTIA Cloud+ course and practice exam: CV0-004
- KCNA course and practice exam: Kubernetes and Cloud Native Associate
- DCA course and practice exam: Docker Certified Associate
- CompTIA Linux+ course and practice exam: XK0-006