DockerInterview preparation
Intermediate·Concept·2 min read

What are layers and multi-stage builds?

Practice this question

Definition:

Docker layers are reusable filesystem changes produced during image creation. Build caching can reuse unchanged earlier work, while multi-stage builds separate compilation tools from the final runtime package. This improves build speed and can reduce production image size and unnecessary software.

Key points:

  • Images reuse filesystem layers; cached build steps speed up rebuilds.

  • Copy dependency manifests before changing app source to improve cache reuse.

  • Multi-stage builds copy only required output into the final image.

  • Use a .dockerignore to avoid sending irrelevant files or local secrets into the build context.

Interview point:

  • Copy dependency manifests before frequently changing source, and explain exactly which build output is needed in the final stage.
Adapted from 09_TESTING_GIT_DOCKER_CLOUD.md · “What are layers and multi-stage builds?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.