A hands-on tutorial repository for learning Docker & Docker Compose with a real multi-container application.
This project demonstrates a simple web application with MySQL database integration using Docker & Docker Compose.
Architecture:
- Web Service: Flask application that connects to MySQL
- MySQL Service: Database backend for data persistence
- Click "Use this template" → "Create a new repository"
- Navigate to your new repository
- Click "Code" → "Codespaces" → "Create codespace on main"
git clone https://github.com/CompPsyUnion/docker-tutorial.git
cd docker-tutorial2. Go through the Docker tutorial in /flask_demo_site to understand how the application works and how the Dockerfiles are set up
In the Codespaces terminal, run:
docker compose up -d# Under the project directory
docker compose up -dIn Codespaces, Access the application at port 35000, you can forward your port to the public internet use "Ports" tab in Codespaces, and click the link provided to open in browser.
Once the services are running:
- Home Page: http://localhost:35000
- MySQL Test: http://localhost:35000/mysql
.
├── docker-compose.yml # Multi-service configuration
├── src/
│ ├── app.py # Flask application
│ └── Dockerfile # Web service image definition
└── README.md
# Start all services in background
docker compose up -d
# View service status
docker compose ps
# View logs (all services)
docker compose logs -f
# View logs (specific service)
docker compose logs -f web
# Stop all services
docker compose down
# Stop and remove volumes
docker compose down -v
# Rebuild and restart
docker compose up -d --buildThe web service uses the following environment variables to connect to MySQL:
| Variable | Description | Default |
|---|---|---|
MYSQL_HOST |
MySQL server hostname | mysql |
MYSQL_PORT |
MySQL server port | 3306 |
MYSQL_USER |
Database username | root |
MYSQL_PASSWORD |
Database password | 123456 |
MYSQL_DATABASE |
Database name | testdb |
MIT License - see LICENSE for details.