Skip to content
DevPlainly
Self-Hosting

What Is Docker? Containers Explained Simply

What Docker is, explained with one picture: houses vs apartments. Images, containers and Dockerfiles in plain words, plus a real test and first commands.

Published
Reading time
7 min read
Contents
  1. The picture: houses vs apartments
  2. The words you need
  3. We tested it: ten containers in 1.6 seconds
  4. What problems Docker solves
  5. Your first Docker commands
  6. What Docker is not
  7. FAQ
  8. Is Docker a virtual machine?
  9. Is Docker free?
  10. What's the difference between an image and a container?
  11. Do I need Linux to use Docker?
  12. Is Docker hard to learn?
  13. Further reading

Docker is a tool that runs applications in containers: small, isolated boxes that carry an app and everything it needs, and that start in about a second. If you've heard "it works on my machine" one too many times, Docker is the usual answer.

This guide explains what Docker is with one simple picture, the handful of words you need (image, container, Dockerfile), what happened when we started ten containers on a real machine, and the first commands to try.

Nil's note

I use Docker every day. In class we run Odoo and MySQL with it, and I keep old projects in compose files so I can bring any of them back with one command instead of reinstalling everything. For trying whole operating systems like Arch or Debian, though, I use VirtualBox, and the difference between the two is exactly what this guide explains.

The picture: houses vs apartments

Imagine you need to give three apps somewhere to live.

  • A virtual machine is a whole house. Each app gets its own plot, its own foundations, its own walls, plumbing and roof. In computer terms, every virtual machine runs a complete operating system of its own. It's very isolated, but heavy: each one takes gigabytes and has to boot like a real computer.
  • A container is an apartment. All the apps live in one building and share the foundations and the plumbing, which is the host's operating system kernel. Each one still gets its own door, its own rooms and its own key. Because nobody builds new foundations, an apartment is ready almost immediately and takes up very little space.

That's the whole idea of Docker: isolation like separate homes, at the cost of an apartment.

The words you need

WordWhat it isIn the picture
ImageA read-only package with an app and everything it needs: files, libraries, settingsThe floor plan of an apartment
ContainerA running copy of an image, isolated from the othersAn apartment someone lives in
DockerfileA text file with the steps to build an imageThe instructions to draw the plan
RegistryA place to share images, like Docker HubA catalog of floor plans
VolumeStorage that survives when a container is removedA storage room outside the apartment
Docker ComposeA file that starts several containers togetherThe building's plan with all its apartments

One image can start as many containers as you like, the same way one floor plan can be used for many identical apartments.

We tested it: ten containers in 1.6 seconds

To see how light containers are, we built the smallest possible image and started ten copies of it with Docker Engine 29 on a Linux machine. The image holds only BusyBox, a single program that provides the basic Linux commands:

FROM scratch
COPY busybox /bin/busybox
RUN ["/bin/busybox", "--install", "-s", "/bin"]
CMD ["sh"]
docker build -t tiny-linux .
for i in $(seq 1 10); do docker run -d --name app$i tiny-linux sleep 3600; done
docker stats --no-stream
MeasureResult
Image size1.15 MB
Time to start all ten containers1.6 seconds
Memory used by each running containerAbout 290 KB
Kernel version inside a container6.18.44, the same as the host

Two results explain everything:

  • The kernel version inside the container is the host's. The container didn't boot an operating system; it borrowed the one already running. Those are the shared foundations.
  • Each container only sees itself. Running ps inside one shows a single process, numbered 1. The other nine are invisible to it. That's the apartment's own door.
$ docker run --rm tiny-linux sh -c 'uname -r; ps'
6.18.44-fc-v310
PID   USER     COMMAND
    1 0        {ps} sh -c uname -r; ps

A real app uses more memory than our tiny test, because the app itself needs it. What it doesn't need is a second operating system, and that's where the savings come from. For the full comparison with virtual machines, see Docker vs virtual machines.

What problems Docker solves

  • "It works on my machine." The image carries the exact versions of everything the app needs, so it runs the same on your laptop, your classmate's and the server.
  • Installing databases and tools. Instead of installing PostgreSQL, MySQL or Redis on your computer, you start a container and delete it when you're done. Nothing is left behind.
  • Running old projects. A compose file brings back a project with its database and its exact versions, even years later.
  • Deploying. Most hosting platforms and servers run containers, so the same image goes from your laptop to production.

Your first Docker commands

Install Docker Desktop on Windows or macOS, or Docker Engine on Linux, then try these:

docker run hello-world                 # downloads a test image and runs it
docker run -d -p 8080:80 nginx         # a web server at http://localhost:8080
docker ps                              # list running containers
docker stop <container-id>             # stop one
docker images                          # list the images you've downloaded

The next step is running several containers together, like an app with its database, which is what Docker Compose is for. Docker Compose for beginners walks you through your first one, and two free tools can write the files for you: the Dockerfile generator and the Docker Compose generator.

What Docker is not

  • It isn't a virtual machine. Containers share the host's kernel. That's why they're light, and also why a Linux container needs a Linux kernel underneath.
  • On Windows and macOS there's a small VM after all. Docker Desktop runs a lightweight Linux virtual machine in the background (on Windows, through WSL 2), and your containers live inside it. You don't have to manage it, but it's why Docker uses more memory on those systems than on Linux.
  • It isn't the best fit for desktop apps. Docker shines with servers, databases and command-line tools. Apps with windows and buttons are better installed normally.
  • It doesn't keep data by itself. Anything written inside a container disappears when you remove it, unless you use a volume. Backing up Docker volumes shows how to keep that data safe.

FAQ

Is Docker a virtual machine?

No. A virtual machine runs a complete operating system on virtual hardware. A container is a group of isolated processes that share the host's kernel. That's why a container starts in about a second and a virtual machine has to boot.

Is Docker free?

Docker Engine, the part that runs containers, is open source and free. Docker Desktop, the app for Windows and macOS, is free for personal use, education, non-commercial open-source projects and small businesses; larger companies need a paid subscription.

What's the difference between an image and a container?

An image is the package, like a floor plan: it doesn't run. A container is a running copy of that image, like an apartment built from the plan. One image can start many containers.

Do I need Linux to use Docker?

No. Docker Desktop runs on Windows and macOS. Behind the scenes it uses a small Linux virtual machine, because most containers need a Linux kernel.

Is Docker hard to learn?

The basics take an afternoon: running a container, mapping a port and writing a simple Dockerfile. Compose files come next. Networking and production deployments take longer, but you don't need them to start.

Further reading

Written by Nil Martinez

Developer · DAM & DAW student

Developer studying multiplatform (DAM) and web (DAW) application development. I work every day with TypeScript, Angular, React, Java, Python, FastAPI, MySQL and Docker on Kubuntu, and I write about the tools I actually use.

How I test and write each guideGitHub

Keep reading