Interview Q&A / Docker & Kubernetes

INTERVIEW Q&A · 67 QUESTIONS

Docker & Kubernetes interview questions

Images, containers, Dockerfiles, pods and deployments, from first principles.

  1. Why do Dockerfiles chain commands with && in one RUN instruction?

    Each RUN creates a layer, and deleting files in a later layer does not shrink the image. Chaining install and cleanup in one RUN means the temporary files never get stored in any layer.

    BeginnerQuick answer1 min read
  2. How can you see what is making up the size of a Docker image?

    docker history lists every layer with its command and size. For file-level detail, the open-source tool dive shows what each layer adds or wastes, which helps you spot big leftovers.

    IntermediateQuick answer1 min read
  3. What is a multi-stage build in Docker and why use it?

    A multi-stage build uses several FROM lines in one Dockerfile. You compile in a heavy build stage, then COPY --from only the finished output into a small final stage, so compilers and source never ship.

    IntermediateQuick answer1 min read
  4. What is the difference between alpine, slim and distroless base images?

    alpine is a tiny distro using musl libc and apk. slim variants are trimmed Debian images using glibc. distroless images contain only your app and its runtime, with no shell or package manager, giving the smallest attack surface.

    IntermediateQuick answer1 min read
  5. Your Docker image is 1.5 GB. How would you reduce its size?

    Use a smaller base image, a multi-stage build, a .dockerignore, install only production dependencies, chain and clean package installs in one RUN, and inspect layers with docker history or dive to find the heavy ones.

    IntermediateQuick answer1 min read