This Docker setup provides both MySQL and PostgreSQL databases running in separate containers for comprehensive database development and testing.
📁 Important: All infrastructure files are located in the
infrastructure/
directory. Navigate there to run Docker commands.
- MySQL Container: Ubuntu 22.04 with MySQL (port 3307)
- PostgreSQL Container: PostgreSQL 15 (port 5433)
- dbt Container: dbt Core with PostgreSQL adapter for data transformation
- Pre-configured: Ready-to-use database instances with default databases and users
- Persistent Storage: Data persists between container restarts for both databases
- Sample Data: PostgreSQL includes sample tables with test data and dbt models
- Network Isolation: All services run on a shared Docker network
- Port:
3307
(host) →3307
(container) - Root Password:
rootpassword
- Database:
myapp
- User:
appuser
- User Password:
apppassword
- Port:
5433
(host) →5432
(container) - Database:
myapp
- User:
appuser
- User Password:
apppassword
- Sample Tables:
users
,posts
with test data
- Container:
dbt-container
- dbt Version: 1.7.4 with PostgreSQL adapter
- Connected to: PostgreSQL database
- Project: Includes staging models (
stg_users
,stg_posts
) and marts (user_post_summary
) - Profile: Pre-configured to connect to PostgreSQL
# Navigate to infrastructure directory
cd infrastructure
# Build and start all containers (MySQL, PostgreSQL, and dbt)
docker-compose up -d
# View logs for all services
docker-compose logs -f
# View logs for specific service
docker-compose logs -f mysql
docker-compose logs -f postgres
docker-compose logs -f dbt
# Stop all containers
docker-compose down
# Stop and remove volumes (WARNING: This will delete all data)
docker-compose down -v
# Check both containers are running (from infrastructure directory)
docker-compose ps
# Verify ports are listening
netstat -an | Select-String "3307|5433"
# Navigate to infrastructure directory
cd infrastructure
# Build the image
docker build -t mysql-custom .
# Run the container
docker run -d \
--name mysql-container \
-p 3307:3307 \
-e MYSQL_ROOT_PASSWORD=rootpassword \
-e MYSQL_DATABASE=myapp \
-e MYSQL_USER=appuser \
-e MYSQL_PASSWORD=apppassword \
mysql-custom
# View logs
docker logs -f mysql-container
# Stop the container
docker stop mysql-container
# Remove the container
docker rm mysql-container
# Test dbt connection to PostgreSQL
docker exec -it dbt-container dbt debug
# Run all dbt models
docker exec -it dbt-container dbt run
# Run dbt tests
docker exec -it dbt-container dbt test
# Interactive dbt shell
docker exec -it dbt-container bash
- Staging Models:
stg_users
,stg_posts
(materialized as views) - Marts Models:
user_post_summary
(materialized as table) - Sources: Configured to reference PostgreSQL
users
andposts
tables - Tests: Data quality tests for uniqueness, null checks, and referential integrity
# Using MySQL client (if installed on host)
mysql -h 127.0.0.1 -P 3307 -u appuser -p
# Using Docker exec
docker exec -it mysql-container mysql -u appuser -p
- Host:
localhost
or127.0.0.1
- Port:
3307
- Username:
appuser
- Password:
apppassword
- Database:
myapp
- Username:
root
- Password:
rootpassword
# Using PostgreSQL client (if installed on host)
psql -h 127.0.0.1 -p 5433 -U appuser -d myapp
# Using Docker exec
docker exec -it postgres-container psql -U appuser -d myapp
- Host:
localhost
or127.0.0.1
- Port:
5433
- Username:
appuser
- Password:
apppassword
- Database:
myapp
-- List all users
SELECT * FROM users;
-- List all posts with user information
SELECT p.title, p.content, u.username
FROM posts p
JOIN users u ON p.user_id = u.id;
-- Query dbt staging models
SELECT * FROM stg_users;
SELECT * FROM stg_posts;
-- Query dbt marts model
SELECT * FROM user_post_summary;
For easy database management, you can use:
- MySQL: See infrastructure/data_sources/DBEAVER_CONNECTION.md for detailed setup
- PostgreSQL: See infrastructure/data_sinks/POSTGRES_CONNECTION.md for detailed setup
- pgAdmin (PostgreSQL): Web-based administration tool
- MySQL Workbench (MySQL): Official MySQL GUI tool
- phpMyAdmin (MySQL): Web-based administration tool
- MySQL: Data stored in named volume
mysql_data
, logs in./mysql-logs
- PostgreSQL: Data stored in named volume
postgres_data
, logs in./postgres-logs
- Network: Both databases communicate via
database-network
bridge network - Data persists between container restarts and rebuilds
This setup is specifically optimized for Windows CloudPC environments:
- MySQL binds to
0.0.0.0:3307
for proper GUI application connectivity - PostgreSQL configured for external connections on port 5433
- Both services avoid default ports to prevent conflicts
# Check both containers
docker-compose ps
# Check specific container
docker ps | findstr mysql
docker ps | findstr postgres
# All services (from infrastructure directory)
docker-compose logs
# Specific service
docker-compose logs mysql
docker-compose logs postgres
# Follow logs in real-time
docker-compose logs -f mysql
docker-compose logs -f postgres
# MySQL container
docker exec -it mysql-container bash
# PostgreSQL container
docker exec -it postgres-container bash
# Test MySQL
docker exec mysql-container mysql -u appuser -papppassword -e "SELECT 'MySQL Connected' AS status;"
# Test PostgreSQL
docker exec postgres-container psql -U appuser -d myapp -c "SELECT 'PostgreSQL Connected' AS status;"
# Check if ports are listening (Windows)
netstat -an | Select-String "3307|5433"
# Check if ports are listening (PowerShell alternative)
Get-NetTCPConnection | Where-Object {$_.LocalPort -eq 3307 -or $_.LocalPort -eq 5433}
- Change Default Passwords: Update all default passwords in environment variables
- Network Security: Implement proper firewall rules and network isolation
- SSL/TLS: Enable encrypted connections for both MySQL and PostgreSQL
- Backup Strategy: Implement automated backup procedures for both databases
- User Privileges: Follow principle of least privilege for database users
- Monitoring: Set up proper logging and monitoring for both database systems
docker_playground/
├── infrastructure/ # All infrastructure files
│ ├── docker-compose.yml # Multi-service container orchestration
│ ├── README.md # Infrastructure overview
│ ├── data_sources/ # Data source configurations
│ │ ├── Dockerfile # MySQL container configuration
│ │ ├── DBEAVER_CONNECTION.md # MySQL DBeaver setup guide
│ │ └── README.md # Data sources documentation
│ ├── data_sinks/ # Data sink configurations
│ │ ├── init-postgres.sql # PostgreSQL initialization script
│ │ ├── POSTGRES_CONNECTION.md # PostgreSQL connection guide
│ │ └── README.md # Data sinks documentation
│ └── dbt/ # dbt (Data Build Tool) configurations
│ ├── Dockerfile.dbt # dbt container configuration
│ ├── DBT_SETUP.md # dbt setup and usage guide
│ └── README.md # dbt documentation
├── data_transformations/ # dbt project directory (data transformation layer)
│ ├── dbt_project.yml # dbt project configuration
│ ├── profiles.yml # dbt connection profiles
│ ├── models/ # dbt models
│ │ ├── staging/ # Staging models and sources
│ │ └── marts/ # Business logic models
│ └── target/ # dbt compilation outputs
├── mysql-logs/ # MySQL log files (created at runtime)
├── postgres-logs/ # PostgreSQL log files (created at runtime)
├── README.md # This file
├── .gitignore # Git ignore rules
└── .git/ # Git repository
This multi-database setup supports various development scenarios:
- Database Migration Testing: Test applications moving from MySQL to PostgreSQL or vice versa
- Multi-Database Applications: Applications that need to work with both database types
- Data Transformation: Use dbt to build data models, transformations, and analytics
- Learning and Comparison: Learn differences between MySQL and PostgreSQL
- Microservices: Different services using different database technologies
- Data Pipeline Development: Build and test data pipelines with dbt
- Data Synchronization: Test data sync between different database systems