Getting Started with Docker
This guide will help you install Docker, run your first container, and learn essential Docker commands.
Installation
macOS
Docker Desktop (Recommended):
- Visit https://docs.docker.com/desktop/install/mac-install/
- Download Docker Desktop for Mac (Intel or Apple Silicon)
- Open the
.dmgfile and drag Docker to Applications - Launch Docker Desktop
- Docker icon appears in menu bar when running
Verify Installation:
Alternative: Homebrew:
Windows
Docker Desktop (Recommended):
- Visit https://docs.docker.com/desktop/install/windows-install/
- Download Docker Desktop for Windows
- Run installer
- Enable WSL 2 (Windows Subsystem for Linux) if prompted
- Restart computer
- Launch Docker Desktop
System Requirements:
- Windows 10 64-bit: Pro, Enterprise, or Education (Build 19041 or higher)
- OR Windows 11 64-bit: Home, Pro, Enterprise, or Education
- WSL 2 enabled
- Hyper-V enabled (automatic)
Verify Installation:
Linux (Ubuntu/Debian)
Install Docker Engine:
Post-Install Steps (run Docker without sudo):
Install Docker Compose:
Your First Container
Hello World
Run the classic first container:
What happened?:
Explanation:
Interactive Container
Run Ubuntu container with interactive shell:
Inside the container:
Flags explained:
-i: Interactive (keep STDIN open)-t: Allocate pseudo-TTY (terminal)ubuntu: Image namebash: Command to run
Background Container
Run Nginx web server in background:
Test it:
Manage the container:
Essential Docker Commands
Image Management
Container Management
Inspecting Containers
Executing Commands in Containers
Building Your First Image
Create a Simple Python App
1. Create application files:
app.py:
requirements.txt:
2. Create Dockerfile:
3. Build the image:
4. Run the container:
Understanding the Build Process
What happens during docker build:
View build history:
Using Docker Compose
Multi-Container Application
Scenario: Flask app + PostgreSQL database
1. Project structure:
app.py (updated):
requirements.txt (updated):
docker-compose.yml:
2. Run the application:
3. Manage services:
Working with Volumes
Persistent Data
Problem: Container data is lost when container is removed
Solution: Use volumes
Named Volume Example:
Bind Mount Example
Development workflow with live code reload:
Networking
Container Communication
Default bridge network:
Custom bridge network (recommended):
List networks:
Cleaning Up
Remove Unused Resources
Common Issues & Solutions
Issue: Port Already in Use
Issue: Container Exits Immediately
Issue: Cannot Connect to Container
Issue: Permission Denied
Next Steps
Learning Path
- Practice building images: Create Dockerfiles for different languages
- Use Docker Compose: Set up multi-container applications
- Explore Docker Hub: Find official images for databases, tools
- Learn networking: Understand how containers communicate
- Study volumes: Master persistent data storage
- Security: Learn image scanning, secrets management
- Orchestration: Move to Kubernetes or Docker Swarm
Recommended Practice Projects
- Containerize existing app: Take a simple app and dockerize it
- Multi-tier app: Web + API + Database with Docker Compose
- Development environment: Database, cache, message queue
- Data pipeline: Airflow + dbt + PostgreSQL
- Microservices: Multiple services communicating
Resources
- Official Documentation: https://docs.docker.com/
- Docker Hub: https://hub.docker.com/
- Play with Docker: https://labs.play-with-docker.com/ (browser-based playground)
- Docker Samples: https://github.com/docker/awesome-compose
Ready for advanced topics? Check out:
- Use Cases - Real-world Docker scenarios
- Best Practices - Production patterns and optimization
- Tutorials - Hands-on projects