Interview Q&A / Docker & Kubernetes

INTERVIEW Q&A · 67 QUESTIONS

Docker & Kubernetes interview questions

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

  1. What is the difference between the -v and --mount flags in Docker?

    Both attach storage. -v is a compact colon-separated string, while --mount uses explicit key=value pairs. --mount is clearer and errors if a bind path is missing, while -v silently creates the host folder.

    IntermediateQuick answer1 min read
  2. Why does localhost inside a container not reach a database running on your laptop?

    Inside a container, localhost means the container itself, not the host. To reach a host service use host.docker.internal (Docker Desktop, or with --add-host on Linux), or put both on a Docker network and use the service name.

    IntermediateQuick answer1 min read
  3. Why is running a container as root dangerous even though it is isolated?

    Root inside a container is still UID 0 on the shared host kernel. A kernel bug, a bad mount or extra capabilities can let an attacker turn that into host access. Running as non-root removes much of that risk.

    IntermediateQuick answer1 min read
  4. Why should you create a user-defined bridge network instead of using the default one?

    On a user-defined bridge, containers resolve each other by name through Docker's built-in DNS, and you get better isolation. On the default bridge you must use IP addresses or legacy links.

    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
  6. How would you back up the data in a Docker volume?

    Run a temporary container that mounts the volume and a host folder, then tar the volume contents into the host folder. Restore by extracting that archive into a volume.

    AdvancedQuick answer1 min read