🐳 Docker for Beginners: Complete Tutorial
Learn Docker from scratch with this hands-on tutorial designed for complete beginners. In 30 minutes, you’ll understand containers, images, and essential commands.
📋 What You’ll Learn
| Topic | Time | Difficulty |
|---|---|---|
| What is Docker? | 5 min | 🟢 Easy |
| Installing Docker | 5 min | 🟢 Easy |
| Your First Container | 10 min | 🟢 Easy |
| Docker Images | 5 min | 🟢 Easy |
| Essential Commands | 5 min | 🟢 Easy |
🤔 What is Docker?
Docker is a tool that makes it easy to create, deploy, and run applications in containers.
Think of it like this:
| Without Docker | With Docker |
|---|---|
| “Works on my machine” problems | Runs the same everywhere |
| Complex setup instructions | One command to run |
| Version conflicts | Isolated environments |
| Hours of configuration | Minutes to get started |
Key Concepts
Container 📦
A lightweight, standalone package that includes everything needed to run an application: code, runtime, libraries, and settings.
Image 📸
A template for creating containers. Think of it as a snapshot or blueprint.
Docker Hub 🌐
A public registry where you can find and share Docker images.
💻 Installing Docker
macOS
- Download Docker Desktop for Mac
- Double-click the
.dmgfile - Drag Docker to Applications
- Open Docker from Applications
- Wait for Docker to start (whale icon in menu bar)
Windows
- Download Docker Desktop for Windows
- Run the installer
- Enable WSL 2 if prompted
- Restart your computer
- Open Docker Desktop
Linux (Ubuntu)
# Update packages
sudo apt update
# Install Docker
sudo apt install docker.io
# Start Docker
sudo systemctl start docker
sudo systemctl enable docker
# Add your user to docker group (logout required)
sudo usermod -aG docker $USER
Verify Installation
Open your terminal and run:
docker --version
You should see something like:
Docker version 24.0.6, build ed223bc
🚀 Your First Container
Let’s run your first Docker container!
Step 1: Run Hello World
docker run hello-world
What happens:
- Docker looks for the
hello-worldimage locally - Doesn’t find it, downloads from Docker Hub
- Creates a container from the image
- Runs the container
- Container prints a message and exits
Output:
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
🎉 Congratulations! You just ran your first container!
Step 2: Run an Interactive Container
Let’s run Ubuntu in a container:
docker run -it ubuntu bash
Flags explained:
-i= Interactive (keep STDIN open)-t= Allocate a terminalubuntu= The image namebash= The command to run
You’re now inside an Ubuntu container! Try some commands:
# Check the OS
cat /etc/os-release
# See processes
ps aux
# Exit the container
exit
Step 3: Run a Web Server
Let’s run Nginx (a web server):
docker run -d -p 8080:80 nginx
Flags explained:
-d= Detached (run in background)-p 8080:80= Map port 8080 on your machine to port 80 in container
Test it: Open http://localhost:8080 in your browser
You should see “Welcome to nginx!”
📸 Understanding Docker Images
What is an Image?
An image is a read-only template for creating containers. Think of it like:
- A class in programming (image) vs. an object (container)
- A recipe (image) vs. a cooked meal (container)
Finding Images
Docker Hub (hub.docker.com) has thousands of pre-built images:
| Image | Description | Usage |
|---|---|---|
nginx |
Web server | docker run nginx |
node |
Node.js runtime | docker run node |
python |
Python runtime | docker run python |
postgres |
PostgreSQL database | docker run postgres |
redis |
Redis cache | docker run redis |
ubuntu |
Ubuntu OS | docker run ubuntu |
Pulling Images
Download an image without running it:
docker pull python:3.11
The :3.11 is a tag specifying the version.
Listing Images
See all downloaded images:
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest a6bd71f48f68 2 weeks ago 187MB
ubuntu latest 174c8c134b2a 3 weeks ago 77.9MB
hello-world latest 9c7a54a9a43c 2 months ago 13.3kB
🛠️ Essential Docker Commands
Container Management
| Command | Description |
|---|---|
docker run <image> |
Create and start a container |
docker ps |
List running containers |
docker ps -a |
List all containers (including stopped) |
docker stop <id> |
Stop a running container |
docker start <id> |
Start a stopped container |
docker rm <id> |
Remove a container |
docker logs <id> |
View container logs |
docker exec -it <id> bash |
Execute command in running container |
Image Management
| Command | Description |
|---|---|
docker images |
List all images |
docker pull <image> |
Download an image |
docker rmi <image> |
Remove an image |
docker build -t name . |
Build image from Dockerfile |
System Commands
| Command | Description |
|---|---|
docker system prune |
Remove unused data |
docker volume ls |
List volumes |
docker network ls |
List networks |
🎯 Hands-On Practice
Exercise 1: Run a Python Script
# Create a simple Python script
echo 'print("Hello from Docker!")' > hello.py
# Run it in a Python container
docker run -v $(pwd):/app -w /app python:3.11 python hello.py
Flags explained:
-v $(pwd):/app= Mount current directory to /app in container-w /app= Set working directory to /app
Exercise 2: Run a Node.js App
# Create package.json
echo '{"name":"test","scripts":{"start":"node index.js"}}' > package.json
# Create index.js
echo 'console.log("Hello from Node.js!")' > index.js
# Run with Node
docker run -v $(pwd):/app -w /app node:18 npm start
Exercise 3: Clean Up
# Stop all running containers
docker stop $(docker ps -q)
# Remove all stopped containers
docker rm $(docker ps -aq)
# Clean up unused resources
docker system prune -f
📚 Quick Reference Card
# 🚀 Run Containers
docker run nginx # Run nginx
docker run -d nginx # Run in background
docker run -p 8080:80 nginx # Map ports
docker run -it ubuntu bash # Interactive shell
docker run -v /host:/container img # Mount volume
# 📋 List & Inspect
docker ps # Running containers
docker ps -a # All containers
docker images # All images
docker logs <container> # View logs
# 🛑 Stop & Remove
docker stop <container> # Stop container
docker rm <container> # Remove container
docker rmi <image> # Remove image
# 🧹 Cleanup
docker system prune # Remove unused data
docker volume prune # Remove unused volumes
🔜 Next Steps
Ready to level up? Continue your Docker journey:
- Learn Dockerfiles - Create your own images
- Docker Compose - Manage multi-container apps
- Docker Volumes - Persist data
- Docker Networks - Connect containers
Related Quests
- Container Fundamentals Quest - Deep dive into Docker
- Docker Compose Orchestration - Multi-container apps
- Frontend Docker Quest - Docker for web development
❓ Common Issues
“Cannot connect to Docker daemon”
Solution: Make sure Docker Desktop is running (look for whale icon).
“Permission denied”
Linux Solution:
sudo usermod -aG docker $USER
# Then log out and back in
“Port already in use”
Solution: Use a different port:
docker run -p 8081:80 nginx # Use 8081 instead of 8080
🎉 Congratulations!
You’ve learned the Docker basics! You can now:
- ✅ Understand containers and images
- ✅ Run containers from Docker Hub
- ✅ Use essential Docker commands
- ✅ Map ports and mount volumes
- ✅ Troubleshoot common issues
| Last Updated: December 2025 | Author: IT-Journey Team |
Found this helpful? Check out our Docker Mastery Quest Series for advanced topics! 🚀