RUN
The Dockerfile instruction that runs a command during the build and saves the result as a new layer.
In more detail
Use it to install packages or compile code: RUN apk add --no-cache curl. Each RUN is one layer, so chain related commands with && and clean caches in the same RUN, otherwise deleted files stay in the earlier layer. RUN --mount=type=secret gives a command a secret without storing it in the image.
Examples
RUN chmod +x app.shRUN apk add --no-cache curlRUN CGO_ENABLED=0 go build -o /out/app .RUN ./mvnw -B -ntp package -DskipTestsRelated terms
- Dockerfile — A text file of instructions, such as FROM, COPY and RUN, that tells Docker how to build an image.
- layer — One read-only slice of an image that records the files a single build step added, changed or deleted.
- build cache — Saved results of earlier build steps that a build tool, such as Docker, reuses when nothing a step depends on has changed.
- package manager — A tool that installs, updates and removes software together with what it depends on, such as apt on Debian, apk on Alpine or Homebrew on macOS.
- build secret — A password or token given to one build step without being saved in any image layer.
- exec form — Writing RUN, CMD or ENTRYPOINT as a JSON list such as ["python", "app.py"], so the program runs directly without a shell.
- multi-stage build — A Dockerfile with several FROM stages, where later stages copy only what they need from earlier ones.
Taught in
- Building and Pushing Container Images — Continuous Integration & Continuous Delivery Pipelines
- Container Images The Exam Way — Certified Kubernetes Application Developer (CKAD) 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
- Union Filesystems, Images And Writable Layers — Docker Architecture & Production Containers
- FROM, WORKDIR, COPY And ADD — Docker Architecture & Production Containers
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- ARG, ENV, LABEL, EXPOSE And VOLUME — Docker Architecture & Production Containers
- CMD, ENTRYPOINT, USER And Process Signals — Docker Architecture & Production Containers
- Multi Stage Builds, Targets And Build Secrets — Docker Architecture & Production Containers
- Minimal Bases, Non Root Users And Smaller Images — Docker Architecture & Production Containers
- Shipping in Scratch and Distroless Images — Concurrent Systems Programming with Go
- Packaging Into A Container — Modern Java: Virtual Threads & High-Throughput Services
- From docker run To docker service: Replicas, Global Mode And Updates — Docker Certified Associate (DCA) Exam Prep
- 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
- Images Sprint: Eight Questions On Builds, Tags And Registries — Docker Certified Associate (DCA) Exam Prep
- Friday, Nine In The Morning: The Mock Exam And Its Report — Docker Certified Associate (DCA) Exam Prep
- Works On My Laptop: Images, Containers, Volumes And Networks — CompTIA Linux+ (XK0-006) Exam Prep