Getting Started with Docker
Introduction
Welcome to the first lesson of Docker Fundamentals. In this lesson, you will learn what containers are, how they differ from virtual machines, and why developers use them in modern software development. You will also get hands-on experience by running your first container using Docker CLI commands. Since you are working in the CodeSignal environment, Docker is already installed for you. However, it is important to know how to check for Docker on any machine, as you may need to do this on your own computer in the future.
Understanding Docker fundamentals is essential before moving on to Google Cloud Platform (GCP) container services such as Artifact Registry, Cloud Run, and Google Kubernetes Engine (GKE). These services all build on core Docker concepts, so having a solid grasp of how containers work will make it much easier to use and troubleshoot these GCP tools effectively.
By the end of this lesson, you will be able to explain what a container is, describe how containers differ from virtual machines, understand why containers are useful, and run a simple "hello world" container using Docker CLI to confirm Docker is working.
What Is A Container?
A container is a lightweight, isolated environment that allows you to run an application and all its dependencies together. Think of it as a small, self-contained box that holds everything your app needs to work: the code, libraries, and settings. This means your app will run the same way, no matter where you start the container.
To make this idea more concrete, imagine a shipping container. No matter what is inside — a car, electronics, or furniture — the container looks the same from the outside and can be moved easily by ship, train, or truck. In the same way, a software container standardizes how applications are packaged and moved, making it easy to run them anywhere.
Containers Vs. Virtual Machines
You might have heard of virtual machines (VMs) before. Both containers and virtual machines help you run software in isolated environments, but they do it in different ways. A virtual machine includes a full copy of an operating system, the application, and all its dependencies. This makes virtual machines large and slow to start.
Containers, on the other hand, share the host operating system and include only the application and its dependencies. This makes containers much smaller and faster to start. You can think of it like this: if your computer is a building, a virtual machine is like building a new house inside it, while a container is like setting up a new room with everything you need, using the building's existing walls and utilities.
Here's a simple mental model to help you compare:
| Layer | Virtual Machine | Container |
|---|---|---|
| Hardware | Host | Host |
| Host OS | Host OS | Host OS |
| Virtualization Layer | Hypervisor | Container Engine (Docker) |
| Guest OS | Full OS per VM | No separate guest OS; shares host kernel |
| App + Dependencies | Inside VM | Inside Container |
The diagram below visualizes this layered architecture:
Notice how the virtual machine stack includes a complete Guest OS for each VM, while containers share the host kernel directly through the Container Engine. This key difference is what makes containers more lightweight and efficient.
