SteelReed

Search

Search posts, questions…

DevOps & CloudQuestion 11 / 35

Junior

What is a Dockerfile, and which instructions does a basic one contain?

Short answer

A Dockerfile is the recipe for an image: which base image, what to copy, which commands to run at build time, and which program runs when the container starts. docker build reads it top to bottom, each instruction is a cached step.

FROM: base imageCOPY: add filesRUN: runs at buildmakes a layerENV, WORKDIR, USERmetadata onlyENTRYPOINT / CMDruns at start

3 points to say:

  1. Only RUN, COPY, ADD create layers; when an instruction changes, it and every one after it rerun.
  2. RUN runs at build, CMD/ENTRYPOINT run at start; prefer COPY over ADD, and ENTRYPOINT in exec form.
  3. .dockerignore and instruction order (rarely-changing things first) decide build speed.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.