π³ 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:
You should see something like:
π Your First Container¶
Let's run your first Docker container!
Step 1: Run Hello World¶
What happens:
1. Docker looks for the hello-world image locally
2. Doesn't find it, downloads from Docker Hub
3. Creates a container from the image
4. Runs the container
5. Container prints a message and exits
Output:
π Congratulations! You just ran your first container!
Step 2: Run an Interactive Container¶
Let's run Ubuntu in a container:
Flags explained:
- -i = Interactive (keep STDIN open)
- -t = Allocate a terminal
- ubuntu = The image name
- bash = The command to run
You're now inside an Ubuntu container! Try some commands:
Step 3: Run a Web Server¶
Let's run Nginx (a web server):
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:
The :3.11 is a tag specifying the version.
Listing Images¶
See all downloaded 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:
"Port already in use"¶
Solution: Use a different port:
π 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! π