Back to Blog
DockerDevOpsInterview Prep

Docker Basics for Developers: Interview Questions & Container Concepts

May 22, 2026·9 min read

Docker has become a foundational skill for backend and DevOps interviews. Even purely backend roles now expect candidates to know how to containerize an application, understand the difference between images and containers, and work with Docker Compose for local development. DevOps and platform engineering roles go deeper, multi- stage builds, networking, security hardening, and Kubernetes integration.

This guide covers the Docker concepts you need to understand for technical interviews, with practical examples for each.

1. Containers vs Virtual Machines

This is almost always the first Docker question: "What is the difference between a container and a VM?" The key distinction:

  • Virtual machines run on a hypervisor and include a full guest OS, gigabytes of disk space, minutes to boot, full kernel isolation.
  • Containers share the host OS kernel via Linux namespaces and cgroups, they isolate processes, filesystems, and networks but do not need their own OS. They start in seconds and use megabytes, not gigabytes.
Follow-up question: "If containers share the kernel, how is isolation achieved?" Namespaces (pid, net, mnt, uts, ipc, user) restrict what a process can see. Cgroups limit CPU, memory, and I/O. Together they make containers feel isolated without full VM overhead.

2. Images vs Containers

Another foundational question: images are immutable templates stored in layers; containers are running instances of images with a writable layer on top.

  • An image is built from a Dockerfile, then pushed to a registry.
  • Multiple containers can run from the same image simultaneously , they share the read-only layers but each gets its own writable layer.
  • When a container is deleted, its writable layer is lost unless you used a volume to persist data.

3. Writing a Dockerfile

Interviewers often ask you to walk through a Dockerfile for a simple Node.js application and identify any problems.

dockerfile
# ── Stage 1: build ────────────────────────────────────────────
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev          # install production deps only
COPY . .

# ── Stage 2: runtime (lean image) ──────────────────────────────
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app .     # copy from builder
USER node                      # run as non-root for security
EXPOSE 3000
CMD ["node", "server.js"]

Key decisions to explain to an interviewer:

  • Alpine base image, minimal OS, ~5 MB vs ~300 MB for Debian-based images. Smaller attack surface and faster pulls.
  • Copy package.json first, Docker caches each layer. If only source files change (not dependencies), Docker reuses the cached npm ci layer, making builds much faster.
  • Multi-stage build, keeps the final image clean of build tools, dev dependencies, and intermediate files.
  • USER node, never run as root in containers. If an attacker exploits your app, they should not have root on the host.

4. CMD vs ENTRYPOINT

dockerfile
# ENTRYPOINT sets the process that always runs.
# CMD provides default arguments, overridable at docker run time.
ENTRYPOINT ["node"]
CMD ["server.js"]

# docker run myapp              → runs: node server.js
# docker run myapp migrate.js   → runs: node migrate.js (CMD overridden)

5. Docker Compose

Docker Compose orchestrates multi-container apps in a single YAML file. Essential for local development, define your app, database, and cache together.

yaml
services:
  app:
    build: .
    ports: ["3000:3000"]
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/mydb
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    volumes:
      - db_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U user"]
      interval: 5s
      retries: 5

volumes:
  db_data:
depends_on with a healthcheck condition waits until the database is actually ready to accept connections, not just started. Without this, your app may crash on startup if it tries to connect before Postgres finishes initializing.

6. Volumes and Data Persistence

Containers are ephemeral, data written to the container filesystem is lost when it is removed. Volumes solve this:

  • Named volumes, managed by Docker, stored in the Docker area. Best for databases.
  • Bind mounts, map a host path into the container. Best for development (live code reloading).
  • tmpfs mounts, stored in host memory only. Best for sensitive temporary data.

7. Top Docker Interview Questions

  • What is the difference between a container and a VM?
  • Explain the difference between CMD and ENTRYPOINT.
  • What is a multi-stage Docker build and why would you use one?
  • How do you persist data in Docker containers?
  • What is Docker Compose and how is it different from Kubernetes?
  • How do containers on the same Docker network communicate?
  • What security best practices should you follow when writing Dockerfiles?
Enjoyed this guide?

Test what you just learned with a timed Docker quiz.