A comprehensive collection of Docker examples demonstrating containerization concepts from basic single-container applications to advanced multi-stage builds and orchestration with Docker Compose. This repository provides hands-on examples for learning Docker fundamentals and best practices.
- Project Overview
- Repository Structure
- Docker Examples
- Getting Started
- Learning Path
- Prerequisites
- Contributing
This repository serves as a practical learning platform for Docker containerization, covering:
- Basic Containerization with single-service applications
- Multi-container Applications using Docker Compose
- Production Optimization with multi-stage builds
- Service Orchestration and networking
- Real-world Applications (APIs, report generators, caching)
- Docker Best Practices and optimization techniques
Docker-Examples/
βββ π docker-basics/ # Simple Flask app containerization
βββ π dynamic-report-generator/ # CSV report generation API
βββ π flask-redis-app/ # Multi-service app with Docker Compose
βββ π multistage-pdf-generator/ # Optimized builds with multi-stage
βββ π readme-docker.md # Docker fundamentals guide
βββ π README.md # This file
Docker Basics π
Simple Flask App Containerization
Basic introduction to Docker containerization with a minimal Python Flask application.
Features:
- β Simple Dockerfile - Basic container setup
- β Flask Web App - "Hello World" web application
- β Port Mapping - Exposing application to host
- β Image Building - Creating custom Docker images
Quick Start:
cd docker-basics
docker build -t hello-docker .
docker run -p 5000:5000 hello-dockerAccess: http://localhost:5000
API-Based CSV Report Generation
Demonstrates building a REST API that generates CSV reports from JSON input.
Features:
- β REST API - POST endpoint for data processing
- β JSON to CSV - Dynamic report generation
- β File Downloads - CSV file response handling
- β Lightweight Container - Optimized Python image
Quick Start:
cd dynamic-report-generator
docker build -t dynamic-report-generator .
docker run -p 5000:5000 dynamic-report-generatorAPI Usage:
curl -X POST http://localhost:5000/generate-report \
-H "Content-Type: application/json" \
-d '[{"name":"John","age":30,"city":"NYC"}]'Flask + Redis App π
Multi-Service Application with Docker Compose
Advanced example showing service orchestration with Docker Compose, featuring a Flask web app connected to Redis for caching.
Features:
- β Docker Compose - Multi-container orchestration
- β Service Networking - Container-to-container communication
- β Redis Integration - Caching and data persistence
- β Dependency Management - Service startup ordering
- β Volume Mapping - Data persistence across restarts
Quick Start:
cd flask-redis-app
docker-compose up --buildAccess: http://localhost:5000 (view counter increments with each refresh)
Services:
- Flask App: Web application server
- Redis: In-memory data store for caching
Production-Optimized Multi-Stage Build
Demonstrates advanced Docker techniques using multi-stage builds to create minimal, production-ready images.
Features:
- β Multi-Stage Build - Separate build and runtime environments
- β Image Optimization - Smaller final image size
- β PDF Generation - Dynamic PDF creation with FPDF
- β Security Best Practices - Minimal attack surface
- β Production Patterns - Optimized for deployment
Quick Start:
cd multistage-pdf-generator
docker build -t pdf-generator .
docker run -p 5000:5000 pdf-generatorBuild Stages:
- Builder Stage: Install dependencies and build artifacts
- Runtime Stage: Copy only necessary files for execution
Windows/Mac:
- Download Docker Desktop from docker.com
- Follow installation instructions for your platform
Linux:
# Ubuntu/Debian
sudo apt update
sudo apt install docker.io docker-compose
# CentOS/RHEL
sudo yum install docker docker-compose# Check Docker version
docker --version
# Check Docker Compose version
docker-compose --version
# Test Docker installation
docker run hello-worldgit clone https://github.com/TheDataArtisanDev/Docker-Examples.git
cd Docker-Examples# Start with basic example
cd docker-basics
docker build -t hello-docker .
docker run -p 5000:5000 hello-dockerVisit http://localhost:5000 to see your containerized application!
- Docker Concepts: Read readme-docker.md for theory
- Basic Container: Docker Basics example
- Docker Commands: Build, run, and manage containers
- API Development: Dynamic Report Generator
- Multi-Container Apps: Flask + Redis
- Service Networking: Understanding container communication
- Build Optimization: Multistage PDF Generator
- Production Deployment: Security and performance considerations
- Orchestration: Docker Compose and service management
- Image Optimization: Multi-stage builds and layer caching
- Security Practices: Minimal base images and user permissions
- Monitoring: Health checks and logging strategies
# Build image
docker build -t <image-name> .
# List images
docker images
# Remove image
docker rmi <image-name>
# Pull from registry
docker pull <image-name># Run container
docker run -p <host-port>:<container-port> <image-name>
# List running containers
docker ps
# Stop container
docker stop <container-id>
# Remove container
docker rm <container-id># Start services
docker-compose up
# Build and start
docker-compose up --build
# Stop services
docker-compose down
# View logs
docker-compose logs <service-name># Execute shell in running container
docker exec -it <container-id> /bin/bash
# View container logs
docker logs <container-id>
# Inspect container
docker inspect <container-id>- Docker Engine 20.10+
- Docker Compose 2.0+
- Git for repository cloning
- Web Browser for testing applications
- RAM: 4GB minimum, 8GB recommended
- Storage: 10GB free space for images
- OS: Windows 10+, macOS 10.14+, or modern Linux
# Docker development tools
docker stats # Resource monitoring
docker system df # Disk usage
docker system prune # Cleanup unused resources- π Application Containerization: Package web apps with dependencies
- π Development Environment: Consistent dev environments across teams
- π Deployment: Simplified application deployment
- ποΈ Service Isolation: Independent service deployment
- π‘ API Integration: Container-to-container communication
- π Load Balancing: Scaling individual services
- βοΈ Build Automation: Containerized build environments
- π§ͺ Testing: Isolated testing environments
- π¦ Artifact Management: Version-controlled container images
This repository focuses on Docker education and practical examples. Contributions welcome:
- π‘ New Examples: Add more Docker patterns or use cases
- π Bug Fixes: Improve existing examples or documentation
- π Documentation: Enhance explanations or add tutorials
- π§ Optimizations: Performance improvements or best practices
For major changes, please open an issue first to discuss your ideas.
- Docker Official Documentation
- Docker Compose Documentation
- Docker Best Practices
- Dockerfile Reference
- Docker Hub
Happy Containerizing! π³
This repository provides a comprehensive journey through Docker containerization. Use these examples to build production-ready containerized applications!