LearnAI ToolsCareerPractice BuildsPlayDevelopmentContact
Lesson 112 min read

Introduction to Docker and Containers

Learn what Docker and containers are, the problem they solve, how they differ from virtual machines, and run your first container.

On this page 10 sections

Introduction

Docker is a tool for packaging an application together with everything it needs to run — the language runtime, libraries, system tools and settings — into a single unit called a container image. That image runs the same way on your laptop, a colleague’s computer, a test server and the cloud. Docker is now a standard part of how software is built and deployed, and it is the foundation for Kubernetes and most modern DevOps tooling.

What You Will Learn
  • The problem Docker solves, and why teams adopted it so quickly.
  • What images, containers and registries are.
  • How containers differ from virtual machines.
  • How to run your first container, and what happens when you do.
Real Output Throughout

Every command in this course was actually run with Docker Engine 29.9 on Ubuntu 24.04, and each output box shows exactly what the terminal printed. You will follow Priya as she packages her own Python web API and runs it with a database. Container IDs, random names and timings will be different on your machine.

The Problem Docker Solves

Priya has built a small Python web API. It runs perfectly on her laptop. On her colleague’s computer it fails: he has a different Python version, a library is missing, and an environment variable is not set. On the server, it fails in yet another way. This is the famous “it works on my machine” problem, and before containers, teams lost countless hours to it.

Docker’s answer is to ship the environment with the application. Priya describes everything her API needs in a short text file called a Dockerfile, Docker builds that into an image, and anyone with Docker can run the image and get exactly the same environment — same Python version, same libraries, same settings.

Without containersWith Docker
Install the right language version on every machineThe runtime is inside the image
Follow a long setup document, and hope nothing is missedOne command: docker run
Two projects need different versions of the same tool — conflictEach container has its own isolated copy
The server is configured differently from your laptopThe same image runs everywhere
Removing an app leaves files scattered across the systemRemove the container and it is gone

Images, Containers and Registries

Four words come up constantly with Docker. It is worth getting them straight now:

TermWhat it isAnalogy
ImageA read-only package: a filesystem with the app and everything it needs, plus the command to start itA recipe, or a class in programming
ContainerA running (or stopped) instance of an image, isolated from other processesA dish cooked from the recipe, or an object created from a class
DockerfileA text file with step-by-step instructions for building an imageWriting down the recipe
RegistryA server that stores and shares images. Docker Hub is the default public oneA cookbook library, or an app store

You can start many containers from one image, just as you can create many objects from one class. Each container gets its own writable layer on top of the image, so changes inside one container never affect the image or other containers.

Containers vs Virtual Machines

A virtual machine (VM) emulates a whole computer and runs a complete operating system, including its own kernel. A container is much lighter: it is an ordinary process on the host, isolated using features of the Linux kernel, and it shares the host’s kernel instead of bringing its own.

Virtual machineContainer
ContainsA full operating system with its own kernelThe app and its files; shares the host kernel
Typical sizeGigabytesMegabytes
Start-up timeTens of seconds to minutesUsually under a second
IsolationVery strong (separate kernel)Strong, but the kernel is shared
Best forRunning different operating systems, strong isolationPackaging and running applications

You can see the shared kernel for yourself. Priya runs Ubuntu under WSL 2 on her Windows laptop. Here is her system’s distribution and kernel version:

grep PRETTY_NAME /etc/os-release
uname -r
Output

Click Run to see what this code prints.

Now the same two commands inside a container made from the tiny Alpine Linux image (the first run downloads it):

docker run --rm alpine sh -c "grep PRETTY_NAME /etc/os-release; uname -r"
Output

Click Run to see what this code prints.

Inside the container the distribution is Alpine — its own files and tools — but the kernel version is identical, because the container is a process running on Priya’s kernel. (Her kernel name mentions Microsoft because WSL 2 provides it; on a Linux computer you would see your distribution’s kernel.) This is also why Linux containers need a Linux kernel: on Windows and macOS, Docker Desktop runs a small Linux virtual machine behind the scenes.

Mini Challenge · Spot the Problem

Which statement about containers is NOT true?

Choose one answer

Your First Container

Lesson 2 shows how to install Docker. Once it is installed, the traditional first command is docker run hello-world. It runs a tiny image whose only job is to explain what just happened:

docker run hello-world
Output

Click Run to see what this code prints.

  • Unable to find image ... locally — Docker checked your computer first and did not have the image.
  • Pulling from library/hello-world — so it downloaded (pulled) it from Docker Hub. The hexadecimal lines are the image’s layers.
  • Digest: sha256:... — a fingerprint that uniquely identifies this exact version of the image.
  • Then it created a container from the image and ran it; the container printed the message and exited.

Run the same command again and the download lines disappear — the image is now stored locally, so the container starts immediately.

How Docker Works

Docker has a client–server design. The docker command you type is the client. It sends requests to the Docker daemon (dockerd), a background service that does the real work: pulling images, building them, and creating and running containers. The daemon in turn uses lower-level tools, containerd and runc, to start the container processes. Because the client and daemon talk over an API, the same docker command can control Docker on your laptop or on a remote server.

Mini Challenge · Put It in Order

Put the steps Docker takes for “docker run hello-world” in order (the first time it runs).

  1. The daemon looks for the image on your computer and does not find it
  2. The daemon pulls the image from Docker Hub
  3. The docker client sends the request to the Docker daemon
  4. The daemon creates a container from the image
  5. The container runs and its output is sent back to your terminal

Where Docker Is Used

  • Development: start a database, cache or any service with one command instead of installing it on your computer.
  • Testing and CI/CD: build and test every change in a clean, identical environment.
  • Deployment: ship the exact image you tested to servers and cloud platforms.
  • Microservices: run each part of a large system in its own container.
  • Kubernetes: the most popular platform for running containers at scale — it runs the same images you build with Docker.

Frequently Asked Questions

Docker Engine, the command-line tool and Docker Compose are free and open source. Docker Desktop, the app for Windows and macOS, is free for personal use, education and small businesses; larger companies need a paid subscription. Check Docker’s website for the current terms.

No. A virtual machine runs a whole operating system with its own kernel. A container is an isolated process that shares the host’s kernel, which is why it is much smaller and faster.

It helps a lot, because most images are Linux-based and you will use Linux commands inside containers. If you are new to the command line, the Linux & Command Line course is a good companion.

Docker builds images and runs containers, usually on one machine. Kubernetes runs and manages containers across many machines — restarting them, scaling them and rolling out updates. Most people learn Docker first.

Key Takeaways

  • Docker packages an application with everything it needs, so it runs the same everywhere.
  • An image is a read-only template; a container is a running instance of it.
  • A Dockerfile describes how to build an image; a registry such as Docker Hub stores and shares images.
  • Containers share the host’s kernel, so they are much lighter than virtual machines.
  • docker run pulls the image if needed, creates a container and starts it.

Summary

You now know what Docker is, why it exists and what happens when you run a container. Next, you will install Docker on your own computer and check that it works.

Next Lesson →

Installing Docker on Windows, macOS and Linux