In Module 2, we explored Kubernetes’ core concepts—pods, nodes, and clusters—and used kubectl
to interact with a cluster. Now, we’ll zoom in on containers, the building blocks that Kubernetes manages. We’ll also introduce Docker, the tool used to create and run containers. By the end of this module, you’ll understand what containers are, how they work, and how to run a simple container yourself.
Learning Objectives:
Imagine you’re moving to a new city, and you need to pack your belongings. Instead of dragging your entire house (furniture, appliances, and all), you pack just what you need into a lightweight, portable box. In the world of software, a container is like that box—it holds everything an application needs to run, such as:
Unlike a full virtual machine (VM), which is like moving the entire house (including the operating system), containers are lightweight because they share the host’s operating system. This makes them fast, portable, and efficient.
Analogy: Think of a container as a lunchbox. It holds your sandwich (the app), condiments (libraries), and a napkin (configuration). You can carry it anywhere, and it’s ready to use without needing a full kitchen.
Docker is the most popular tool for creating, running, and managing containers. It’s like the chef who prepares and serves those lunchboxes. Docker provides:
Dockerfile
.Kubernetes uses Docker (or other runtimes like containerd) to run containers inside pods.
In Kubernetes, containers don’t run alone—they’re housed in pods (from Module 2). Here’s how it fits together:
For example, if you want to run a website, you’d:
Let’s try running a container! You have two options: use an online sandbox (no setup required) or install Docker on your computer. For beginners, the sandbox is easier, so we’ll start there.
Option 1: Use Play with Docker (Online Sandbox)
docker run -d -p 80:80 nginx
docker run
starts a container.-d
runs it in the background.-p 80:80
maps port 80 on the host to port 80 in the container.nginx
is the container image (a pre-built web server from Docker Hub).docker ps
docker stop <container-id>
<container-id>
with the ID from docker ps
.Option 2: Install Docker Locally (Optional)
If you prefer to try this on your computer:
docker run -d -p 80:80 nginx
command.http://localhost
in your browser to see the Nginx page.docker ps
and docker stop
as above.Note for Beginners: If you’re not ready to run commands, just follow along. The sandbox is free and requires no setup, so give it a try if you can! We’ll use .these skills in Kubernetes later.
Here’s what happened in the exercise:
nginx
image is a blueprint for the container, like a recipe for a lunchbox. It’s stored on Docker Hub.docker run
creates a container from the image, like making a lunchbox from the recipe.-p 80:80
flag makes the container’s web server accessible on your browser.In the next module, we’ll use Docker to create containers and deploy them to Kubernetes with kubectl
.
A) A full virtual machine with its own operating system.
B) A lightweight package with an app and its dependencies.
C) A Kubernetes cluster component.
A) docker start
B) docker run
C) docker build
Answers: 1-B, 2-B, 3-B
Further Reading
Docker Get Started: https://docs.docker.com/get-started/
Docker Hub: https://hub.docker.com/ (explore public images like nginx
)
Kubernetes Documentation: Containers (https://kubernetes.io/docs/concepts/containers/)
In Module 4, we’ll combine what you’ve learned about containers and Kubernetes by deploying applications with Kubernetes. You’ll use kubectl
to deploy a simple app (like the Nginx web server) to a Kubernetes cluster and see it in action.