Dockerfile for Dockers
A Dockerfile is a text file of instructions such as FROM, COPY, RUN and CMD that docker build executes to produce an image. Each instruction creates a layer, and Docker reuses unchanged layers through its build cache, so instruction order decides how fast rebuilds are.
Stage: Building Images · Part of the Docker roadmap · Last reviewed 19 November 2026
What to learn in Dockerfile
- Write a Dockerfile with FROM, WORKDIR, COPY, RUN, EXPOSE and CMD for a small web app
- Distinguish CMD from ENTRYPOINT and the shell form from the exec form
- Order instructions so dependency installation stays cached when only source code changes
- Exclude files from the build context with a .dockerignore file
- Pass build-time values with ARG and runtime values with ENV
Dockerfile interview questions
Why do you copy package.json before copying the rest of the source in a Node Dockerfile?
Docker caches each layer and invalidates it when its inputs change. Copying only the dependency manifest first and running npm install means that layer stays cached until dependencies change. Editing application code then only rebuilds the later layers, which saves a lot of time.
What is the difference between CMD and ENTRYPOINT?
ENTRYPOINT sets the executable that always runs, while CMD supplies default arguments that can be overridden at docker run. Used together, ENTRYPOINT defines the program and CMD its default flags. A CMD alone is replaced entirely if you pass a command.
Where Dockerfile fits in the Docker roadmap
Dockerfile belongs to the Building Images stage (beginner level), which takes about 12 hours. Dockerfiles.
Other units in this stage
Back to the full Docker roadmap