Founding prices until 15 December: 30% off Pro, locked for life. See pricing

Docker interview questions

4 questions. Images and containers, smaller and safer images, volumes and container networking. Each has a strong answer of about a minute and the points an interviewer listens for.

  1. 01

    What's the difference between a Docker image and a container? And how is a container different from a virtual machine?

    A strong answer

    An image is a read-only template made of layers: the app, its libraries and how to start it. A container is a running instance of an image, a process with its own isolated filesystem, network and limits, plus a thin writable layer on top. Unlike a virtual machine, a container doesn't have its own kernel: it shares the host's kernel and is isolated by namespaces and cgroups. That makes containers much lighter and quick to start, while a VM runs a full operating system on a hypervisor and gives stronger isolation.

    What the interviewer listens for

    • An image is a read-only template. The basic definition of an image.
    • A container is a running instance of it. The basic definition of a container.
    • Containers share the host's kernel. The key difference from a VM, and what makes containers light.
    • VMs run a full OS, so containers are lighter and faster to start. The consequence of sharing the kernel.

    Likely follow-up: “If containers share the kernel, what does that mean for security?”

    Practise answering it
  2. 02

    Your team's Docker image is 1.5 GB. How would you make it smaller, and safer while you're at it?

    A strong answer

    I'd start with the base image: a slim or distroless image instead of a full OS often saves most of the size. Then a multi-stage build: compile in a builder stage with all the tools, and copy only the finished app into a small final image. I'd add a .dockerignore so the build context doesn't drag in .git or node_modules, and clean package caches in the same layer they're created. For safety, the final image runs as a non-root user and has fewer packages, so fewer vulnerabilities to patch.

    What the interviewer listens for

    • Use a smaller base image. The base image is usually most of the size.
    • Use a multi-stage build. Building in one stage and copying only the result leaves compilers and build tools behind.
    • Keep layers clean and use .dockerignore. Shows you know how layers keep files around.
    • Don't run as root. The "safer" half of the question.

    Likely follow-up: “How would you check an image for known vulnerabilities?”

    Practise answering it
  3. 03

    You run Postgres in a container. What happens to the data when the container is removed, and how do you keep it?

    A strong answer

    Anything written inside the container's own filesystem is lost when the container is removed, so a Postgres container without a volume loses its database. To keep it, mount a named volume (or a bind mount) at /var/lib/postgresql/data: the volume lives outside the container, so a new container picks up the same data. A volume still isn't a backup, so I'd also take regular backups with pg_dump or snapshots.

    What the interviewer listens for

    • The container's own filesystem is lost with it. Interviewers want to hear that the writable layer goes away with the container.
    • Use a volume or bind mount. Volumes live outside the container's lifecycle.
    • Back it up anyway. A volume survives the container, not a disk failure or a mistake. Backups still matter.

    Likely follow-up: “When would you use a bind mount instead of a named volume?”

    Practise answering it
  4. 04

    Two containers, an API and a database, need to talk to each other. How do you set that up, and how does the API find the database?

    A strong answer

    I'd put both on the same user-defined network, which Docker Compose does automatically. Docker has a built-in DNS on that network, so the API reaches the database by its name, for example postgres:5432, instead of an IP that changes. Only the API publishes a port to the host with -p; the database stays internal and isn't exposed to the outside.

    What the interviewer listens for

    • Put them on the same user-defined network. Containers on a shared network can reach each other; Compose creates one for you.
    • Use the container or service name. Docker's DNS resolves the container or service name, so no hard-coded IPs.
    • Don't publish the database port publicly. Only the API needs a published port. Exposing the database is a common mistake.

    Likely follow-up: “Why doesn't this work on the default bridge network by name?”

    Practise answering it

Ready for the real thing?

A timed interview asks questions like these one at a time, adds quick questions, a design and a hands-on task on a real machine, and ends with a hire or no-hire scorecard.

Take a practice interview