Your First Steps with Docker
Installation: Setting Up Your Workshop
Installing Docker is like setting up a workshop. You need the right tools for your operating system:
Verifying Your Installation
Like testing a new tool, let's verify Docker is working properly:
Server: Docker Engine - Community
Containers: 0
Images: 0
Server Version: 24.0.7
Hello World: Your First Container
Running your first container is like the "Hello World" of Docker. Let's see what happens behind the scenes:
Interactive Containers: Playing in a Sandbox
Containers can be interactive, like having a temporary computer you can experiment with:
Running Web Applications
Let's run a real web server in a container - nginx, one of the world's most popular web servers:
localhost:8080] B[Docker] end subgraph "Container" C[nginx
Port 80] end A -->|Request| B B -->|Port mapping
8080:80| C C -->|Response| B B -->|Web page| A style A fill:#4caf50 style C fill:#2196f3
Container Management Commands
Think of these commands as your remote control for containers:
Real World Example: Running a Database
Let's run a PostgreSQL database - something that traditionally takes time to install and configure:
Container Lifecycle in Practice
Let's see how containers behave through their lifecycle with a practical example:
Practical Exercise: Multi-Container Application
Let's run a WordPress site with MySQL - a real-world application setup:
--name mysql-db \
--network wordpress-net \
-e MYSQL_ROOT_PASSWORD=rootpass \
-e MYSQL_DATABASE=wordpress \
-e MYSQL_USER=wpuser \
-e MYSQL_PASSWORD=wppass \
mysql:8.0
--name wordpress-app \
--network wordpress-net \
-p 8000:80 \
-e WORDPRESS_DB_HOST=mysql-db \
-e WORDPRESS_DB_USER=wpuser \
-e WORDPRESS_DB_PASSWORD=wppass \
-e WORDPRESS_DB_NAME=wordpress \
wordpress
Understanding Container Isolation
Containers are isolated from each other and the host system. It's like having separate apartments in a building:
Common Patterns and Best Practices
Troubleshooting Tips
When things don't work as expected, here's your debugging toolkit:
Common Issues and Solutions
Container exits immediately?
Check logs: docker logs container-name
Can't connect to service?
Verify port mapping: docker port container-name
Container using too much memory?
Set limits: docker run -m 512m image-name
Need to debug inside container?
Execute bash: docker exec -it container-name bash
Image taking too much space?
Clean up: docker system prune -a
Your Container Cheat Sheet
Key Takeaways
You've learned to:
✅ Install and verify Docker
✅ Run your first containers
✅ Use interactive containers
✅ Expose services with port mapping
✅ Manage container lifecycle
✅ Run multi-container applications
✅ Debug and troubleshoot containers
Remember: Containers are lightweight, isolated environments that start in seconds. They're perfect for development, testing, and production deployments!
What's Next?
Now that you're comfortable running containers, in the next lesson we'll learn how to build your own custom images with Dockerfiles - turning your applications into portable containers!