

Lab 005: Docker Compose - WordPress & MariaDB ¶
This lab demonstrates how to use Docker Compose to orchestrate a simple multi-container application: WordPress with a MariaDB database backend.
Overview¶
-
The provided
docker-compose.yamlfile defines two main services: -
db: Runs a MariaDB database (can be switched to MySQL if desired).
-
wordpress: Runs the latest WordPress application, connected to the database.
-
A named volume
db_datais used to persist database data.
docker-compose.yaml Breakdown¶
- db service
- Uses the
mariadb:10.6.4-focalimage (or optionally MySQL). - Sets up environment variables for root password, database, user, and password.
- Persists data in a Docker volume.
-
Exposes ports 3306 and 33060 (internal only).
-
wordpress service
- Uses the latest WordPress image.
- Maps port 80 on the host to port 80 in the container.
-
Configures environment variables to connect to the database.
-
volumes
db_data: Persists MariaDB data between container restarts.
Bonus Demo¶
- I prepared a demo of this lab, which you can view on KillerCoda: Portainder Demo.
- The demo is showcases for setting and running multuple containers using Docker Compose
- The demo is available on KillerCoda.
How to Run the Lab¶
-
Navigate to the lab directory:
-
Start the services:
-
This will pull the required images (if not already present) and start both the database and WordPress containers in detached mode.
-
Access WordPress:
- Open your browser and go to http://localhost
-
Complete the WordPress setup wizard.
-
Stop the services:
This will stop and remove the containers, but the database data will persist in thedb_datavolume.
Notes¶
- To use MySQL instead of MariaDB, uncomment the relevant line in the compose file and comment out the MariaDB image line.
- The database credentials are set for demonstration purposes. For production, use secure passwords.
- The
dbservice is only accessible to thewordpressservice (not exposed to the host).
Troubleshooting¶
- If you encounter port conflicts, ensure nothing else is running on port 80.
- To view logs for a service:
This lab is part of the DockerLabs series. See other labs for more Docker scenarios and hands-on exercises.
