Docker Basics: Containers Made Simple
What Is Docker?
In this lesson you will
- Explain what a container is
- Tell containers and virtual machines apart
- Define image and container
Introduction
"It works on my machine!" is a famous developer complaint. An app runs on one computer and breaks on another because of different versions of tools and libraries. Docker solves this by packaging an app together with everything it needs to run.
It helps to be comfortable with the command line before this course.
The simple explanation
A container is a lightweight, isolated box that holds an app and its dependencies, and runs the same way everywhere.
Think of a shipping container. Whatever is inside, the outside is a standard size, so any ship, train or lorry can carry it. A software container is standard in the same way, so any computer with Docker can run it.
Image and container
- An image is the template: a read-only package with your app, its tools and settings.
- A container is a running instance of an image.
It is like a recipe and a meal. One image can start many containers.
Containers vs virtual machines
A virtual machine (VM) includes a whole operating system for each copy, so it is heavy and slow to start. Containers share the host computer's operating system kernel and only package the app and its libraries. They are smaller, start in seconds, and you can run many on one machine.
Containers are isolated from each other, but they are not as strongly separated as VMs. Treat security seriously.
Quick quiz
What is the relationship between an image and a container?
Why developers use Docker
- Same everywhere: the app runs the same on a laptop, a test server and in the cloud.
- Easy setup: start a database in one command, with no manual install.
- Clean: try tools without cluttering your computer, then remove them.
- Sharing: images are published in registries such as Docker Hub, so others can use them.
Install Docker
Install Docker Desktop on Windows or macOS, or Docker Engine on Linux, from docs.docker.com. Then check it works in a terminal:
Terminal
$ docker --versionYou will see a version number. Your number will differ.
Try it yourself
Install Docker and run docker --version. In your own words, explain the difference between an image and a container.
Summary
- A container packages an app with its dependencies and runs the same everywhere.
- An image is the template, and a container is a running copy.
- Containers are lighter than virtual machines because they share the host's kernel.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading