Skip to content
$ lynuxpro

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 196–210 of 475 questions

196.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.

197.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.

198.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.

199.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.

200.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.

201.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.

202.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.

203.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.

204.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.

205.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.

206.What actually isolates a container from the host?SeniorDocker

Linux namespaces (PID, network, mount, UTS, IPC, user) isolate what it sees; cgroups limit what it uses; seccomp, capabilities and AppArmor/SELinux limit what it can do. It shares the host kernel, so kernel exploits can escape; gVisor or Kata add a stronger boundary.

207.Why should a container run one main process, and what is PID 1's job?SeniorDocker

Docker watches PID 1: when it exits, the container stops. PID 1 must handle signals and reap zombie processes; many apps don't, so use exec in entrypoint scripts or --init (tini). One process per container also keeps logs, scaling and restarts simple.

208.What are cgroups and namespaces?SeniorDocker

Namespaces give a container its own view of processes, network, mounts, hostname and users. Cgroups limit and measure its CPU, memory and I/O. Together they make a container: an isolated, limited process on a shared kernel.

209.How do you choose a base image?SeniorDocker

Prefer small, maintained images: distroless or -slim variants, or Alpine if musl is fine for your app. Pin versions or digests, rebuild often to pick up security fixes, and scan images in CI.

210.What is the difference between Docker and containerd, and why did Kubernetes drop dockershim?SeniorDocker

containerd is the container runtime that actually runs containers; Docker Engine adds a CLI, builds and more on top of it. Kubernetes talks to runtimes through CRI, which containerd and CRI-O support directly, so the extra Docker layer (dockershim) was removed in 1.24. Images built with Docker still run unchanged.