DevOps
Docker interview questions on containers, images, Dockerfile, networking, volumes, and Docker Compose for containerised deployments.
What is the difference between a Docker image and a container?
Tip: An image is an immutable, layered template (built from a Dockerfile). A container is a running, writable instance of an image with its own isolated process/network namespace. One image can spawn many containers — like a class vs its objects.
How does Docker differ from a virtual machine?
Tip: A VM virtualises hardware and runs a full guest OS (heavy, slow boot). Containers share the host kernel and isolate only the process/filesystem via namespaces and cgroups — lightweight, fast to start, denser. Containers trade stronger isolation for efficiency.
What are Docker layers and how does build caching work?
Tip: Each Dockerfile instruction creates a cached layer. Docker reuses a layer if the instruction and its inputs are unchanged. Order matters: copy dependency manifests and install BEFORE copying source code, so editing code does not bust the dependency-install cache.
What is a multi-stage build and why use it?
Tip: A multi-stage build uses multiple FROM stages — e.g. build in a heavy SDK image, then COPY only the compiled artifact into a slim runtime image. This shrinks the final image, removes build tools from production, and improves security and pull speed.
How do you persist data in Docker?
Tip: Container filesystems are ephemeral. Use named volumes (managed by Docker, portable, preferred for databases) or bind mounts (map a host path, good for dev). tmpfs keeps data in memory only. Never store stateful data in the container layer.
What is Docker Compose used for?
Tip: Compose defines and runs multi-container apps from a single YAML file (services, networks, volumes, env). docker compose up starts the whole stack (e.g. app + Postgres + Redis) with one command — ideal for local dev and integration testing.
How do you reduce Docker image size?
Tip: Use a slim/alpine or distroless base, multi-stage builds, combine RUN steps and clean package caches in the same layer, add a .dockerignore, and avoid installing unnecessary tools. Smaller images pull faster and have a smaller attack surface.
What is the difference between CMD and ENTRYPOINT?
Tip: ENTRYPOINT sets the fixed executable; CMD provides default arguments (or a default command). At runtime, args after docker run override CMD but are appended to ENTRYPOINT. Use ENTRYPOINT for the binary, CMD for default flags — together they make a configurable container.
InterviewEra generates role-specific questions using your actual projects and skills. Get scored feedback on technical depth, clarity, and structure — free to start.