

Lesson 01 · 12 min
Container, image and first commands
How a container differs from a virtual machine, what an image is, and how to live with docker run, ps, logs, exec.
12 minLesson 1 of 5Practice includedAsk AI on any point
This course takes you from your first docker run to an image you are not ashamed to ship to production. It does not repeat the "Docker and deploy" course: there Docker is just one step on the way to a server, while here we dig into Docker itself: layers, cache, volumes, networks, Compose and image security.
Course plan
- Lesson 1. Container vs virtual machine, image vs container, basic commands.
- Lesson 2. Dockerfile: layers, instruction order and cache, COPY vs ADD, CMD vs ENTRYPOINT.
- Lesson 3. Volumes and networks: bind mount, named volume, DNS between containers, port publishing.
- Lesson 4. Docker Compose: a web app, Postgres and Redis with healthchecks.
- Lesson 5. Smaller and safer images: multi-stage, distroless or alpine, non-root, .dockerignore, scanning.
- Coming later. Registries and image tags, Docker in CI, debugging containers that crash.
A container is not a virtual machine
A virtual machine emulates a whole computer: it has its own OS kernel, takes a minute to boot and occupies gigabytes. A container is an ordinary process on the host that the Linux kernel isolates with namespaces (its own processes, network, file system) and limits with cgroups (CPU, memory). The kernel is shared with the host, so a container starts in a fraction of a second and weighs as much as its files.
Image and container
An image is an immutable template: a file system made of layers plus metadata (which command to run, which environment variables). A container is a running instance of an image with a thin writable layer on top. You can start ten containers from one image, each with its own changes, and the image stays the same. A code analogy: the image is a class, the container is an object.
-druns it in the background,--namegives a readable name instead of a random one.-p 8080:80: port 8080 on the host leads to port 80 in the container. Host first, container second.--rmremoves the container after it stops, handy for one-off commands:docker run --rm -it node:22 node -v.docker logsshows stdout and stderr of the main process. That is why an app in a container writes logs to the console, not to a file.
- Docker in the knowledge base: a short reference
- Podman: a compatible daemonless alternative
- Docker or Podman: comparison
Check
Lock it in before you move on
1. What fundamentally sets a container apart from a virtual machine?
2. How many containers can you start from one image?
3. What does
-p 3000:80mean?4. Why does a container running
npm start &stop right away?