🐳 Docker Beginner

What is docker build and how does it work?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Docker basics — a prerequisite for any developer role.

Answer

docker build reads the Dockerfile and builds a Docker image from it. Syntax: docker build [options] path. The path (typically . for the current directory) defines the build context — the set of files sent to the Docker daemon. Process: (1) Docker sends the build context to the daemon (respecting .dockerignore); (2) The daemon reads the Dockerfile instructions in order; (3) Each instruction creates a new layer; (4) Layers are cached — if an instruction and context hash match a cached layer, it's reused (cache hit). Key options: -t myapp:1.0 / --tag — name and tag the resulting image; -f Dockerfile.prod / --file — specify a different Dockerfile; --no-cache — ignore all cached layers (build fresh); --build-arg KEY=value — pass ARG values; --target stage_name — build only up to a specific stage (multi-stage builds); --platform linux/amd64 — build for a specific architecture; --pull — always pull the latest base image. Build context tip: if the build context is large, specify it precisely: docker build -f docker/Dockerfile . or docker build --no-context with STDIN for small projects. Use docker buildx for multi-platform builds.

Common Mistake

Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Docker candidates.