Learn Docker from scratch with this hands-on tutorial designed for complete beginners. In 30 minutes, you’ll understand containers, images, and essential commands.
| 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 |
Docker is a tool that makes it easy to create, deploy, and run applications in containers.
| 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 |
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.
.dmg file# 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
Open your terminal and run:
docker --version
You should see something like:
Docker version 24.0.6, build ed223bc
Let’s run your first Docker container!
docker run hello-world
What happens:
hello-world image locallyOutput:
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
🎉 Congratulations! You just ran your first 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 runYou’re now inside an Ubuntu container! Try some commands:
# Check the OS
cat /etc/os-release
# See processes
ps aux
# Exit the container
exit
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 containerTest it: Open http://localhost:8080 in your browser
You should see “Welcome to nginx!”
An image is a read-only template for creating containers. Think of it like:
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 |
Download an image without running it:
docker pull python:3.11
The :3.11 is a tag specifying the version.
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
| 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 |
| 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 |
| Command | Description |
|---|---|
docker system prune |
Remove unused data |
docker volume ls |
List volumes |
docker network ls |
List networks |
# 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# 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
# 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
# 🚀 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
Ready to level up? Continue your Docker journey:
Solution: Make sure Docker Desktop is running (look for whale icon).
Linux Solution:
sudo usermod -aG docker $USER
# Then log out and back in
Solution: Use a different port:
docker run -p 8081:80 nginx # Use 8081 instead of 8080
You’ve learned the Docker basics! You can now:
| Last Updated: December 2025 | Author: IT-Journey Team |
Found this helpful? Check out our Docker Mastery Quest Series for advanced topics! 🚀