← All learning hubsContainers

Learn Docker

Package any app into a portable container that runs the same everywhere.

Overview

Docker is the tooling that popularized Linux containers — a way to package an application with its dependencies into a lightweight, portable image that runs identically across machines. Unlike virtual machines, containers share the host kernel, so they start in milliseconds and use far fewer resources. Docker images are built from a Dockerfile, stored in registries like Docker Hub, and run as isolated container processes.

Learn in this order

Docker roadmap

  1. 1

    Containers vs. virtual machines

    Understand why containers share the host kernel and are lighter and faster than VMs.

  2. 2

    Images and containers

    An image is an immutable template; a container is a running instance of that image.

  3. 3

    Writing a Dockerfile

    Learn FROM, RUN, COPY, WORKDIR, EXPOSE, CMD, and ENTRYPOINT to define reproducible builds.

  4. 4

    Image layers and caching

    Each instruction creates a cached layer; ordering instructions well makes rebuilds fast.

  5. 5

    Multi-stage builds

    Separate build and runtime stages to ship small, secure production images.

  6. 6

    Volumes and persistence

    Named volumes and bind mounts keep data alive beyond a container's lifecycle.

  7. 7

    Networking

    Bridge, host, and none network modes; how containers talk to each other and the outside.

  8. 8

    Docker Compose

    Define and run multi-container apps declaratively with a single compose file.

Get interview-ready

Top Docker interview questions

Real questions with concise, correct answers. Click to expand each.

What is the difference between an image and a container?+

An image is a read-only, immutable template built from a Dockerfile — it packages the app, libraries, and filesystem. A container is a running (or stopped) instance of an image with a thin writable layer on top. You can start many containers from the same image, and changes in a container don't affect the image.

How does a container differ from a virtual machine?+

A VM virtualizes hardware and runs a full guest operating system with its own kernel, managed by a hypervisor. A container virtualizes the OS: it shares the host kernel and isolates processes using namespaces and cgroups. As a result containers are much smaller, start in milliseconds, and pack more densely, but they can't run a different kernel than the host.

What is the difference between CMD and ENTRYPOINT?+

ENTRYPOINT sets the executable that always runs when the container starts; CMD provides default arguments (or a default command) that can be overridden at 'docker run'. A common pattern is ENTRYPOINT for the binary and CMD for its default flags, so users can override the arguments without changing the executable.

What is a multi-stage build and why use it?+

A multi-stage build uses multiple FROM statements in one Dockerfile: an earlier stage compiles or builds the app with all its build tools, and a final, minimal stage copies only the resulting artifacts. This drastically shrinks the final image and reduces attack surface because compilers, dev dependencies, and source code aren't shipped to production.

How do you persist data generated by a container?+

By default a container's writable layer is deleted when the container is removed. To persist data you use volumes: named volumes are managed by Docker and are the preferred option, while bind mounts map a host directory into the container. Both keep data outside the container's lifecycle so it survives restarts and removals.

What is the difference between COPY and ADD in a Dockerfile?+

Both copy files into the image. COPY simply copies local files/directories and is preferred for clarity. ADD does the same but also auto-extracts local tar archives and can fetch remote URLs. Best practice is to use COPY unless you specifically need ADD's tar-extraction behavior.

Keep it handy

Docker cheat sheet

docker build -t app:1.0 .

Build an image from the Dockerfile in the current directory.

docker run -d -p 8080:80 app

Run a container detached, mapping host 8080 to container 80.

docker ps -a

List all containers, including stopped ones.

docker exec -it <id> sh

Open an interactive shell in a running container.

docker logs -f <id>

Stream a container's logs.

docker images

List locally stored images.

docker compose up -d

Start a multi-container app defined in a compose file.

docker system prune

Reclaim space by removing unused containers, networks, and images.

Prove it

Docker certifications

Docker Certified Associate (DCA)

Validates practical skills in image creation, orchestration, networking, storage, and security.

KCNA — Kubernetes and Cloud Native Associate

CNCF entry cert covering containers and the cloud-native ecosystem Docker feeds into.

Ready to ace the interview?

This hub gets you started. Our Docker interview kit goes deeper — hundreds of curated questions, model answers, and mock scenarios built to get you hired.

Keep learning