INTERVIEW PREP
Interview questions
570 questions from real DevOps, SRE, platform engineering and MLOps interviews, with the answer an interviewer wants to hear. Try answering out loud first, then open the model answer.
Showing 151–165 of 490 questions
151.What is the difference between an image and a container?BeginnerDocker
An image is a read-only template made of layers. A container is a running instance of an image with its own writable layer, process namespace and network.
152.What is the difference between CMD and ENTRYPOINT?BeginnerDocker
ENTRYPOINT sets the executable; CMD supplies default arguments (or the default command if there is no ENTRYPOINT). docker run image args replaces CMD but not ENTRYPOINT.
153.What is a Dockerfile, and what do FROM, RUN, COPY and EXPOSE do?BeginnerDocker
A Dockerfile is the recipe for an image. FROM picks the base image, RUN runs a command at build time and saves the result as a layer, COPY adds files from the build context, and EXPOSE documents the port the app listens on (it doesn't publish it).
154.What is the difference between docker stop and docker kill?BeginnerDocker
docker stop sends SIGTERM, waits (10 seconds by default) for a clean shutdown, then sends SIGKILL. docker kill sends SIGKILL right away, so the app can't clean up.
155.How do you keep data when a container is removed?BeginnerDocker
Store it in a volume (-v data:/var/lib/postgresql/data) or a bind mount to a host folder. The container's own writable layer is deleted with the container.
156.What does -p 8080:80 mean?BeginnerDocker
Publish port 80 inside the container on port 8080 of the host, so http://localhost:8080 reaches the app.
157.How do you make images smaller and builds faster?MidDocker
Use multi-stage builds, a small base (slim, distroless, alpine where appropriate), order instructions so rarely changing layers come first, use .dockerignore, and combine package install and cleanup in one RUN.
158.A container exits immediately after starting. How do you debug it?MidDocker
docker ps -a for the exit code, docker logs <id> for output, then docker run -it --entrypoint sh image to look inside. Common causes: the main process runs in the background, a missing env var, or wrong file permissions.
159.How do containers on the same host talk to each other?MidDocker
Put them on the same user-defined bridge network; Docker's embedded DNS resolves container names. The default bridge network has no name resolution.
160.What is a multi-stage build?MidDocker
A Dockerfile with several FROM stages: you build in a big image with compilers, then COPY --from=build only the result into a small runtime image. The final image is smaller and has fewer vulnerabilities.
161.Why does the order of lines in a Dockerfile matter?MidDocker
Each instruction is a cached layer, and a change invalidates every layer after it. Copy dependency files and install dependencies first, then copy the source code, so code changes don't reinstall everything.
162.What is the difference between ADD and COPY?MidDocker
COPY just copies files. ADD can also download URLs and unpack local tar files, which can surprise you. Use COPY unless you need what ADD does.
163.What is Docker Compose used for?MidDocker
It runs a multi-container app from one compose.yaml: services, networks, volumes and environment. It is great for local development and tests, for example an app plus Postgres plus Redis with docker compose up.
164.Why should a container not run as root, and how do you change it?MidDocker
If an attacker breaks out of the app, root in the container makes escaping to the host easier. Create a user and add USER app in the Dockerfile, and in Kubernetes set runAsNonRoot: true.
165.How do you secure container images in a pipeline?SeniorDocker
Pin base images by digest, run as non-root, drop capabilities, scan with Trivy or Grype and fail on critical CVEs, generate an SBOM, sign images with cosign and verify signatures at deploy time.