What is a Dockerfile, and what do the main instructions do?
What they are really testing: Whether you can author a basic image and know the core instructions and that many of them create layers. The foundation for everything else about Docker.
A real interview question
What is a Dockerfile, and what do the main instructions do?
What most people say
drag me
“A Dockerfile is a file with commands that builds a Docker image.”
True but contentless. It cannot name FROM, RUN, COPY, CMD or explain that instructions create layers, which is what the question is actually asking.
The follow-ups they ask next
What is the difference between COPY and ADD?
COPY just copies local files. ADD also fetches URLs and auto-extracts tar archives. The guidance is to prefer COPY for clarity and use ADD only when you specifically need its extra behavior.
Does EXPOSE make a port reachable from outside?
No, EXPOSE is documentation/metadata. To actually reach the port you publish it at runtime with docker run -p host:container (or a Compose ports mapping).
What the interviewer is listening for
- Names FROM/RUN/COPY/CMD with correct roles
- Knows EXPOSE is documentation only
- Knows instructions create layers
What sinks the answer
- Cannot name the core instructions
- Thinks EXPOSE publishes a port
- No notion of layers
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“A Dockerfile is [an ordered recipe of instructions that build an image]. [FROM sets the base, RUN runs build steps, COPY brings in files]. [WORKDIR/ENV configure, EXPOSE only documents a port]. [CMD/ENTRYPOINT set the start process]. Most instructions [create a layer], so order affects build speed and size.”
Keep going with docker
Foundation
What is a container, and how is it different from a virtual machine?
Foundation
What is the difference between a Docker image and a container?
Junior
How does the Docker build cache work, and how do you order a Dockerfile to use it well?
Junior
What is the difference between CMD and ENTRYPOINT, and what is the exec versus shell form?
Junior
How does container networking work in Docker, and how do containers talk to each other?
Junior
How do you persist data in Docker? Explain volumes versus bind mounts.
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free