Site Tools


wiki:docker-dockerfile

Table of Contents

Docker Dockerfile

Dockerfile is a text file listing instructions to build an image. Start with a base image (e.g., FROM ubuntu:22.04), then layer changes on top with RUN, COPY, WORKDIR, ENV, etc. Docker builds the image by executing each instruction sequentially, creating a new layer for each step.

FROM ubuntu:22.04
 
RUN apt-get update && apt-get install -y gcc make
 
COPY . /app
WORKDIR /app
 
RUN make
 
CMD ["./myprogram"]

Each instruction creates a layer. Docker caches layers—rebuilding reuses unchanged layers up to the first change, then re-executes from there. Put instructions that change frequently (like COPY .) near the end to maximize cache hits. Never split apt-get update and apt-get install into separate RUN instructions—the install might use a stale cached update layer.

wiki/docker-dockerfile.md · Last modified: by 127.0.0.1