Skip to main content

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

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.

Back to the full Docker roadmap