Containerization

What is Docker? Containerization Made Easy

Updated June 2026
Shipping Containers Cargo Port Yard
Docker standardizes applications into lightweight, self-contained packages just like shipping containers.

Have you ever heard a developer frustratedly say: "But I swear, it works on my machine!"? This is the oldest and most annoying problem in software development. A programmer writes working code on their Mac, but when they send it to run on a Linux production server, it crashes. Docker was created to kill this problem permanently!

Let's find out how Docker containerizes software to make code work perfectly everywhere.

The Story of the Standard Shipping Container

In the 1950s, cargo shipping was a mess. Workers had to load bags of bananas, barrels of oil, and boxes of toys directly into a ship's hold. It took days, things got wet, barrels leaked, and items were crushed under heavy loads. If a train carried the goods next, everything had to be unpacked and repacked again!

Then came the Standard Shipping Container. It is a strong, metal box of a fixed size. It locks onto ships, trains, and trucks perfectly. The shipping company doesn't care what is inside—whether it's bananas or cars, they just load the standard box. It fits everywhere!

Docker is the shipping container for software. Instead of sending code files separately and hoping the server has the right Python version, you pack your code, libraries, and tools into a single digital container. This container runs identically on any computer or server on Earth!

Real-World Example: Sarah's Chatbot Crash

Sarah writes a chatbot script using Python version 3.9 and installs specific math libraries locally on her Mac. She sends the script to the operations team, but their cloud server runs an older Python version 3.6. The script crashes immediately due to incompatible syntax.

The Docker Solution: Sarah writes a recipe file called a Dockerfile. This file instructs Docker to bundle her chatbot code together with Python 3.9 and the exact math libraries. Docker packages this into a Docker Image. The server runs the image inside a container. The chatbot runs on its own internal Python 3.9 and works perfectly on the first try, ignoring the server's older version!

Docker vs Virtual Machines (VMs)

Before Docker, engineers used Virtual Machines (VMs) to run multiple apps on one server. But VMs are heavy! A VM runs a complete Operating System (like Windows or Ubuntu, costing 5-10GB of space and massive RAM) just to run a tiny 50MB script.

Docker containers share the host computer's operating system core (kernel). This makes containers ultra-lightweight. They start up in a fraction of a second and take up minimal space. You can run hundreds of containers on a single cheap server!

Core Docker Vocabulary

Dockerfile

A text file containing the step-by-step recipe to build your app (e.g. download Python, copy code, set database port).

Docker Image

The read-only, frozen snapshot built from your Dockerfile. It contains your complete app package ready to be run.

Docker Container

The active, live running instance of your image. You can start, stop, delete, and duplicate containers instantly.

Docker Hub

A public online registry (app store) where developers share pre-built images for databases (MySQL), web servers (Nginx), and more.

9 Everyday Docker Commands Every Engineer Needs

To interact with Docker, you run commands in your terminal. Here is a cheat sheet of the 9 commands you will use daily:

Purpose Docker Command Real-World Analogy & Example
Build Image docker build -t <name> . Follows the Dockerfile recipe to bake a frozen image package.
Example: docker build -t my-chatbot .
Run Container docker run -d -p <ports> <image> Spins up a live, running container from an image in the background.
Example: docker run -d -p 80:80 nginx
List Running Containers docker ps Lists all active, running containers currently on the computer.
Example: docker ps (Or docker ps -a for all).
Stop Container docker stop <id> Sends a stop signal to pause and shut down a running container.
Example: docker stop a1b2c3d4
List Local Images docker images Lists all frozen images downloaded or built locally on your machine.
Example: docker images
Download Image docker pull <image> Downloads a pre-built image from Docker Hub (like downloading Nginx or MySQL).
Example: docker pull ubuntu
Upload Image docker push <image> Uploads your custom build image to Docker Hub so others can use it.
Example: docker push my-username/my-chatbot
Enter Container docker exec -it <id> bash Opens a terminal shell inside the running container to debug files.
Example: docker exec -it a1b2c3d4 bash
Delete Container docker rm <id> Deletes a stopped container to free up disk space.
Example: docker rm a1b2c3d4

Pro-Tip for Docker Space

Docker images and containers can consume massive disk space over time. Keep your machine clean by running docker system prune -a to delete all unused images, stopped containers, and cache files safely in one click!

Next Steps on Your DevOps Journey

Now that you can containerize your code and run standard boxes with Docker, you face a new question: How do we manage, coordinate, and scale thousands of these containers across a massive cloud data centre? The answer is Kubernetes orchestration!

Test Your Knowledge

Answer these 25 questions to check your understanding of this module. Click on an option to reveal the correct answer instantly.

Question 1 of 25
Which command builds an image from a Dockerfile?
A. docker create
B. docker build
C. docker run
D. docker make
Explanation: docker build creates an image from a Dockerfile.
Question 2 of 25
Which command lists running containers?
A. docker list
B. docker ps
C. docker run
D. docker show
Explanation: docker ps lists running containers.
Question 3 of 25
How do you stop a container?
A. docker end
B. docker stop
C. docker halt
D. docker kill
Explanation: docker stop gracefully stops a container.
Question 4 of 25
What file is used to define a multi-container application?
A. Dockerfile
B. docker-compose.yml
C. config.json
D. package.json
Explanation: Docker Compose uses a YAML file to define multi-container apps.
Question 5 of 25
Which command removes all stopped containers?
A. docker clean
B. docker rm
C. docker container prune
D. docker delete
Explanation: docker container prune removes all stopped containers.
Question 6 of 25
What does -d flag do in "docker run"?
A. Debug mode
B. Detached mode
C. Delete on exit
D. Direct mode
Explanation: -d runs the container in the background (detached).
Question 7 of 25
Which command downloads an image from a registry?
A. docker get
B. docker pull
C. docker fetch
D. docker load
Explanation: docker pull downloads an image from a registry like Docker Hub.
Question 8 of 25
How do you view logs of a container?
A. docker logs
B. docker view
C. docker history
D. docker show
Explanation: docker logs [container_id] fetches the logs.
Question 9 of 25
What is a Docker Volume?
A. Network config
B. Persistent data storage
C. CPU limit
D. Memory limit
Explanation: Volumes are the preferred mechanism for persisting data.
Question 10 of 25
Which command executes a command inside a running container?
A. docker run
B. docker enter
C. docker exec
D. docker attach
Explanation: docker exec runs a new command in a running container.
Question 11 of 25
What is "FROM" in a Dockerfile?
A. The maintainer
B. The base image
C. The source code
D. The destination
Explanation: FROM initializes a new build stage and sets the Base Image.
Question 12 of 25
Which command lists all images locally?
A. docker images
B. docker list-images
C. docker show
D. docker ps
Explanation: docker images (or docker image ls) lists top-level images.
Question 13 of 25
How do you map a port in docker run?
A. -p host:container
B. -port host:container
C. -m host:container
D. -map host:container
Explanation: -p (or --publish) maps a container port to a host port.
Question 14 of 25
What is a .dockerignore file?
A. Lists errors to ignore
B. Lists files to exclude from the build context
C. Lists ignored containers
D. Lists ignored networks
Explanation: It excludes files and directories from the build context.
Question 15 of 25
Which command removes an image?
A. docker rm
B. docker rmi
C. docker del
D. docker remove
Explanation: docker rmi removes one or more images.
Question 16 of 25
What is Docker Swarm?
A. A virus
B. A container orchestration tool
C. A networking driver
D. A storage driver
Explanation: Docker Swarm is a container orchestration tool native to Docker.
Question 17 of 25
Which network driver is default for containers?
A. host
B. bridge
C. overlay
D. none
Explanation: The default network driver for containers is bridge.
Question 18 of 25
What does "docker inspect" do?
A. Checks container health
B. Returns low-level information
C. Debugs code
D. Inspects file system
Explanation: It returns detailed information on Docker objects.
Question 19 of 25
How to tag an image?
A. docker label
B. docker tag
C. docker name
D. docker mark
Explanation: docker tag creates a tag TARGET_IMAGE that refers to SOURCE_IMAGE.
Question 20 of 25
What is "COPY" in Dockerfile?
A. Copies from one container to another
B. Copies local files to the image
C. Duplicates the image
D. Copies files from URL
Explanation: COPY copies new files/directories from to the filesystem of the container.
Question 21 of 25
Which command pushes an image to a registry?
A. docker upload
B. docker send
C. docker push
D. docker commit
Explanation: docker push uploads an image to a registry.
Question 22 of 25
What does "docker login" do?
A. Starts the daemon
B. Authenticates with a registry
C. Connects to a container
D. Logs container output
Explanation: It logs in to a Docker registry.
Question 23 of 25
What is an "overlay" network?
A. Default network
B. Connects multiple Docker daemons
C. Local network only
D. Testing network
Explanation: Overlay networks connect multiple Docker daemons (Swarm/K8s).
Question 24 of 25
Which instruction executes a command during the build process?
A. CMD
B. RUN
C. ENTRYPOINT
D. EXEC
Explanation: RUN executes commands in a new layer and commits the results.
Question 25 of 25
How to restart a container?
A. docker reload
B. docker restart
C. docker boot
D. docker reset
Explanation: docker restart stops and then starts the container.