Dockerfile
A Dockerfile lists the instructions that docker build follows to create an image. Each instruction (FROM, COPY, RUN, USER, CMD...) adds a layer, and Docker caches the layers that did not change.
Key concepts #
FROMchooses the base image, and severalFROMlines create a multi-stage build.- Build cache: put the instructions that change rarely first.
.dockerignorekeeps files and secrets out of the build context.CMDandENTRYPOINTdefine what the container runs.- BuildKit adds cache mounts, secret mounts and multi-platform builds. See BuildKit and buildx.