Docker Demystified: Your Ultimate Beginner’s Guide to Containers
🚢 Imagine building a ship in a bottle, carefully encapsulating every tiny detail so it sails flawlessly, no matter where it’s displayed. That’s Docker for your applications.
If you’ve ever struggled with software that works on your machine but fails elsewhere, Docker is your lifeboat. And if you have not, then it’s mission is still to save you- a low-tech person who is trying to install something useful shared on Github- from the burden of reading over pages of instruction with manual installing method. Not sure this guide will turn you from a Docker novice to a pro, but at least it might help you to grasp a fundamental understanding about Docker, and be able to use it. And if it doesn’t help, read again.
Let’s dive in!
Why Docker? The Problem Solver
The “Works on My Machine” Nightmare
Picture this: You’ve built a sleek app, tested it thoroughly, and shipped it to your teammate. But on their machine, it crashes. Why?
- Dependency mismatches (they’re using Node.js 14, you used 18)
- OS differences (Linux vs. Windows quirks)
- Configuration drift (environment variables, file paths)
Docker eliminates these headaches by packaging your app and its environment into a single, portable unit, a container.
Before Docker: The VM Era
Virtual Machines (VMs) were the old fix. They emulate entire operating systems, but they’re slow, resource-hungry, and bulky (GBs per VM). Docker containers, by contrast, are lightweight (MBs), share the host OS kernel, and start in seconds.
Docker 101: Containers, Images, and Registries
1. Containers vs. Images
- Image: A read-only template (like a recipe). Examples:
nginx
,python:3.9
. A container image is a standardized package that includes all of the files, binaries, libraries, and configurations to run a container. - Container: A running instance of an image (like a meal cooked from the recipe).
There one thing you should note about images
:
- Images are immutable. Once an image is created, it can’t be modified. You can only make a new image or add changes on top of it.
But luckily, thanks to Watchtower, we can automate this process, this will come in handy later so bookmark it.
2. Docker Registries: The Image Library
Registries store and share images. Docker Hub is the default public registry (think “GitHub for Docker”).
- Public images:
docker pull nginx
grabs the official Nginx What is Nginx? A high-performance open-source web server, reverse proxy, and load balancer widely used to host websites and manage web traffic.image. - Private registries: For proprietary code (e.g., AWS ECR, Google Container Registry).
Advanced Usecase- Push to a Private Registry:
docker tag my-app:latest my-registry.com/my-app:v1
docker push my-registry.com/my-app:v1
3. Image Tagging: Version Control for Containers
Tags specify image versions:
node:18
→ Node.js version 18.my-app:v1.2
→ Your app’s version 1.2.
No tag? Docker defaults to:latest
(but avoid this in production, it’s unpredictable!).
Setting Sail: Installing Docker
We will work with Docker Desktop in this guide, since it’s beginner friendly and basically a no-brainer 1 click install and provide you with almost full features. And if you’re curious what is its alternative, check this
Step-by-Step Installation: Download Docker Desktop ( Windows/Mac/Liniux) for your OS and follow their instruction.
Don’t forget to install any additional requirements (e.g., WSL2 for Docker Desktop on Windows), and make sure your hardware meets the necessary prerequisites.
After installed WSL2
and Docker Desktop
, there’s some setting you should notice
Make sure your Disk Image location
is located where the disk space is generous.
Make sure you WSL integration
setting is turned on.
Docker Commands: Your First Voyage
Essential Commands Cheat Sheet
Command | Description | Example |
---|---|---|
docker pull | Download an image from a registry | docker pull nginx |
docker run | Start a container from an image | docker run -d -p 8080:80 nginx |
docker ps | List running containers | docker ps -a (Add -a to show all containers (including stopped ones)) |
docker stop | Gracefully stop a running container. | docker stop <container-id> |
docker rm | Delete a container | docker rm <container-id> |
docker images | List downloaded images | docker images |
Understanding Key Terms & Commands
What is a “port”?
A port is a virtual endpoint for network communication.
-p 8080:80
maps host port 8080 to container port 80.Access the app via http://localhost:8080 (your machine) → traffic routes to port 80 inside the container.
What does -d mean?
- Runs the container in detached mode (background), freeing up your terminal.
How to open a terminal( assumming you are really a beginner)
- Windows: Use PowerShell, Command Prompt, or Windows Subsystem for Linux (WSL). (for example, in Windows taskbar, type in search
cmd
,bash
..) - macOS/Linux: Use the built-in Terminal app (e.g., Terminal, iTerm, GNOME Terminal).
Or you can use the terminals directly in Docker Desktop.
Now let’s try it
- Run an Nginx Web Server:
# Download the Nginx image (if not already cached):
docker pull nginx
# Start a container in detached mode, mapping port 8080 on your machine to port 80 in the container:
docker run -d -p 8080:80 nginx
- Verify It’s Running:
docker ps # You’ll see your Nginx container’s ID and status.
Access the Server: Open a web browser and go to http://localhost:8080. You’ll see the Nginx welcome page (confirming the container is working!).
Clean Up:
# Stop the container (replace <container-id> with your actual ID from `docker ps`):
docker stop <container-id>
# Delete the container:
docker rm <container-id>
```## **Port Binding: Bridging Containers and Hosts**
Containers run in isolation. To access apps inside them, **map host ports to container ports**:
Pro Tip: Avoid port conflicts! If
8080
is busy, use-p 8081:80
instead. ( Later on, you’ll likely end up with multiple Docker containers or even Docker Compose setups that try to use the same port.)
Want more?
Now head over to GitHub and explore some interesting projects. Try testing them out yourself by following the instructions provided above. I recommend checking out https://github.com/CorentinTh/it-tools - it offers a collection of handy tools, especially useful if you often tinker with internet-related tasks.
(Actually you could just copy and paste their docker command and paste it to the terminal
docker run -d --name it-tools --restart unless-stopped -p 8080:80 corentinth/it-tools:latest
Because when you try to run an image that hasn’t been downloaded yet, it gonna pull the image anyway with the command run
)
If you succeed, you now can access this UI via localhost:8080
on your browser:
Aight, I hope you now have a basic understand about what Docker is, and can run an image yourself. If you don’t, read again, and tryna read some other guides below to expose yourself to these new techy stuffs, and you’ll soon get used to it.
Beyond the Basics: Where to Next?
- Docker Compose: Define multi-container apps (e.g., app + database) with a
docker-compose.yml
file. - Docker Containerize: Learn to build an Image yourself.
- Kubernetes: Orchestrate containers at scale.
- Volumes: Persist data (e.g., databases) beyond container lifetimes.
- Networking: Connect containers securely (custom networks, DNS).
- CI/CD: Docker in the Software Development Lifecycle*
Ahoy! Further Resources
- Docker Official Documentation
- Docker Hub
- TechWorld with Nana’s Docker Course (video guide)
- Awesome Docker (curated tools & tutorials)
Fair winds and following seas! 🐳