Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 111 Β· Getting Started

What Is Docker?

Learn what Docker is, how containers differ from virtual machines, what images and containers are, and why teams use Docker to build, ship and run software.

Every developer has said it at least once: "But it works on my machine." The app runs on your laptop, then fails on a teammate's laptop, on the test server, or in production. The cause is rarely the code itself. It is the environment around the code: a different version of Node or Python, a missing system library, a setting that only exists on one computer.

Docker solves this by letting you package an application together with everything it needs to run (the runtime, libraries, tools and configuration) into one unit, and then run that unit the same way everywhere. In this lesson you will learn what Docker actually is, how a container differs from a virtual machine, the three words you need to know (image, container, registry), and where Docker fits into everyday work.

The problem Docker solves

Imagine you build a small web service in Python. To run it, a computer needs Python 3.12, a few packages at exact versions, and perhaps a system library for image processing. You write down the setup steps in a README. Three weeks later a new colleague follows them on a machine that has Python 3.9, and spends a morning fixing errors.

Now multiply that by ten services, three operating systems, a staging server and a production cluster. Keeping all those environments identical by hand is slow and fragile.

Docker's answer is to make the environment part of what you ship. You describe it once, in a file, and Docker builds a package from it. Anyone who has Docker can run that package, and it behaves the same way on a laptop, in a CI pipeline or on a server.

What Docker is

Docker is a platform for building, distributing and running containers. A container is an ordinary process (or a small group of processes) on a Linux machine that the operating system has isolated from the rest of the system. Inside it, the process sees its own file system, its own network interface, its own list of processes and its own hostname. It feels like a small private computer, but it is much lighter, because there is no second operating system inside.

Three ideas carry most of what you will learn in this tutorial:

  • An image is a read-only template: a file system snapshot plus some metadata such as the default command to run. Think of it as a recipe card that already contains all the ingredients.
  • A container is a running (or stopped) instance of an image. You can start many containers from one image, just as you can start many processes from one program.
  • A registry is a server that stores and shares images. Docker Hub is the best-known public registry.
TEXT
   Dockerfile ──build──▢  IMAGE  ──run──▢  CONTAINER
   (instructions)        (template)        (running process)
                            β”‚
                         push / pull
                            β”‚
                         REGISTRY (Docker Hub, GHCR, your own)

You will build your own images from Dockerfiles later in this tutorial. For now, you only need to remember the direction of the arrows: files become images, images become containers.

Containers versus virtual machines

A virtual machine (VM) emulates a whole computer. A piece of software called a hypervisor divides the hardware between several guests, and each guest runs its own complete operating system, including its own kernel. VMs give strong isolation, but each one needs gigabytes of disk, a chunk of dedicated memory and usually tens of seconds to boot.

A container does not carry a kernel. All containers on a host share the host's Linux kernel, and the kernel's isolation features keep them apart. A container starts in a fraction of a second and an image can be as small as a few megabytes.

TEXT
   Virtual machines                      Containers

 β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”
 β”‚ App β”‚ β”‚ App β”‚ β”‚ App β”‚            β”‚ App β”‚ β”‚ App β”‚ β”‚ App β”‚
 β”‚Libs β”‚ β”‚Libs β”‚ β”‚Libs β”‚            β”‚Libs β”‚ β”‚Libs β”‚ β”‚Libs β”‚
 β”‚Guestβ”‚ β”‚Guestβ”‚ β”‚Guestβ”‚            β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜
 β”‚ OS  β”‚ β”‚ OS  β”‚ β”‚ OS  β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜            β”‚   Container engine  β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 β”‚     Hypervisor      β”‚            β”‚   Host OS (kernel)  β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€            β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 β”‚      Hardware       β”‚            β”‚      Hardware       β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

You can see the shared kernel with two short commands. The first asks a small Alpine Linux container for its kernel version, the second asks an Ubuntu container. These are two different Linux distributions, yet the kernel is identical:

CONSOLE
$ docker run --rm alpine:3.22 uname -r
6.18.54.1-microsoft-standard-WSL2
$ docker run --rm ubuntu:24.04 uname -r
6.18.54.1-microsoft-standard-WSL2

Both report the kernel of the machine that runs them. (On this test machine that is the WSL 2 kernel that Docker Desktop uses on Windows; yours will show a different number.) A container brings its own user space (the files, libraries and programs of a distribution) but borrows the kernel.

Start-up time shows the difference in practice. Once the image is on your disk, running a command in a fresh container takes about a second including the time Docker needs to create the container, run the command and clean up:

CONSOLE
$ time docker run --rm alpine:3.22 echo ready
ready

real    0m1.445s

Your timing will vary, but it will be seconds at most, not minutes.

Virtual machine Container
Includes its own kernel Yes No, shares the host kernel
Typical image size Gigabytes Megabytes to a few hundred megabytes
Start-up time Tens of seconds Often under a second
Isolation Strong (separate kernel) Good, but a shared kernel is a larger attack surface
Can run a different OS than the host Yes Only the same kernel family (Linux containers need a Linux kernel)

Containers are not "lightweight VMs" and they are not a security boundary as strong as a VM. They are isolated processes. The security lessons explain what that means in practice.

Docker on Windows and macOS

Linux containers need a Linux kernel. On Windows and macOS, Docker Desktop therefore runs one small, hidden Linux VM and starts all your containers inside it. You get VM-style isolation once, for the whole Docker environment, and container-style speed for everything inside. On a Linux machine there is no VM at all: containers run directly on your kernel. That is why the output above shows a microsoft-standard-WSL2 kernel on a Windows machine.

Images and containers in practice

The simplest way to feel the difference between an image and a container is to run the same image twice. Each run creates a new container with its own writable layer, so changes in one do not appear in the other:

CONSOLE
$ docker run --name first alpine:3.22 touch /note.txt
$ docker run --name second alpine:3.22 ls /note.txt
ls: /note.txt: No such file or directory
$ docker rm first second
first
second

The file /note.txt was created inside the first container only. The second container started from the same pristine image, so the file does not exist there. The image never changes; every container adds its own temporary changes on top. This is also why data you care about must live in volumes rather than in the container itself.

Compare the sizes of the images used so far:

CONSOLE
$ docker images alpine:3.22
IMAGE         ID             DISK USAGE   CONTENT SIZE   EXTRA
alpine:3.22   2e0b81d60597       12.9MB         3.88MB

(Column headers and layout are what Docker 29 prints; the ID is shortened and the sizes come from the test machine.) A complete Alpine Linux file system takes under 13 MB of disk space, and its compressed content is under 4 MB. Ubuntu 24.04 is about 119 MB on the same machine. Compare that with the gigabytes of a typical VM image.

Why teams use Docker

Docker became standard equipment in software teams for a handful of practical reasons.

Consistency. The image you test is the exact image you deploy. There is no "install these 14 packages first" step to forget.

Fast, clean onboarding. A new developer clones the project and runs one command, and the database, cache and app all start. No more installing PostgreSQL by hand. With Docker Compose you can describe a whole multi-service stack in a single file.

Isolation between projects. Project A needs Node 18 and project B needs Node 24? Each runs in its own container with its own runtime. Nothing is installed on your machine, so nothing conflicts.

Efficient use of servers. Because containers are small and start fast, you can run many more of them on a server than you could VMs. Cleaning up is also trivial: remove the container and everything it did is gone.

A common unit for automation. CI systems, cloud platforms and orchestrators such as Kubernetes all speak "container image". Once your app is an image, you can deploy it on almost any modern platform.

What Docker is not

A few misunderstandings are worth clearing up early.

  • Docker does not make an app faster. A containerized app runs at nearly native speed on Linux, but it will not outperform the same app without a container.
  • Docker is not a replacement for good application design. A container that stores its only copy of important data in its own file system is a bug waiting to happen.
  • Docker does not remove the need to understand your app's dependencies. It records them; you still choose them.
  • Older articles mention Docker CE (Community Edition) and Docker EE (Enterprise Edition). Today the free engine is simply Docker Engine, the enterprise product line was sold to Mirantis in 2019, and paid features now come through Docker Desktop and Docker's business subscriptions. The engine's background process is called dockerd.
  • "Docker" can mean several things: the company, the open-source engine (the daemon and CLI), and Docker Desktop (a desktop application that bundles the engine, a Linux VM, Compose and a graphical dashboard). When someone says "run it in Docker", they usually mean the engine.

Containers are best for software that you can start, stop and replace freely: web apps, APIs, workers, build tools, test databases. For a production database that holds irreplaceable data, containers can work well but need extra care. Running Databases in Containers covers when to do it and when not to.

Where this tutorial goes

You will start by installing Docker and running your first container. Then you will learn how Docker works under the hood, the command line, images and layers, Dockerfiles, storage, networking and Compose, followed by security, CI/CD, language-specific recipes and complete projects. Every command in this tutorial was run against a real Docker Engine (29.x with Compose v5 and BuildKit), and the outputs you see are real, with identifiers shortened and machine-specific values marked.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. What is the main difference between a container and a virtual machine?

    Containers are isolated processes that share the host's Linux kernel. A VM carries a full guest OS including its own kernel, which is why it is larger and slower to start.
  2. 2. How do an image and a container relate?

    You build or pull an image, then create any number of containers from it. Changes made inside one container never modify the image or other containers.
  3. 3. You run docker run alpine:3.22 touch /note.txt and then docker run alpine:3.22 ls /note.txt. Why does the second command not find the file?

    The first container wrote the file into its own writable layer. The second container starts from the pristine image, which has no such file.
  4. 4. Why does Docker Desktop run a small Linux VM on Windows and macOS?

    Containers share the host kernel, so Linux containers need a Linux kernel. Docker Desktop supplies one inside a hidden VM. On a Linux host no VM is needed.

Summary

  • Docker packages an application and its environment so it runs the same way on any machine with Docker.
  • An image is a read-only template; a container is a running (or stopped) instance of an image; a registry stores and shares images.
  • Containers share the host's Linux kernel, so they are small and start in about a second, while VMs boot a full guest OS.
  • Docker Desktop on Windows and macOS runs one hidden Linux VM to host all containers.
  • Containers are isolated processes, not a replacement for VMs when you need the strongest isolation.
  • Data that must survive should not live in a container's own writable layer.

Next: Installing Docker