This project demonstrates how to deploy a multi-container WordPress application using Docker Compose.
The deployment consists of two containers:
- WordPress
- MySQL 8.0
Docker Compose is used to automate the deployment, networking, and management of both containers using a single configuration file (docker-compose.yml).
Throughout this project, Git was used for version control, and the completed project was prepared for publication on GitHub as part of a Cloud/DevOps portfolio.
- Docker
- Docker Compose
- WordPress
- MySQL 8.0
- Git
- GitHub
- Visual Studio Code
Before starting this project, ensure the following software is installed:
- Docker Desktop
- Git
- Visual Studio Code
Verify the installations by running:
docker --version
docker compose version
git --versionwordpress-docker-lab
│
├── docker-compose.yml
├── README.md
└── screenshots/
Create a dedicated project workspace to store all project files, configuration files, documentation, and screenshots.
mkdir wordpress-docker-lab
cd wordpress-docker-lab
code .The following commands were executed:
mkdir wordpress-docker-labcreates a new project directory.cd wordpress-docker-labchanges the current working directory to the project folder.code .opens the project folder in Visual Studio Code.
Using a dedicated project folder keeps all resources organized and makes project management easier.
The project folder was successfully opened in Visual Studio Code, and the Explorer panel displayed the newly created workspace.
Figure 1: Project folder opened in Visual Studio Code.
A dedicated project workspace was successfully created and prepared for the WordPress Docker Compose deployment.
Initialize a local Git repository to enable version control and prepare the project for publication on GitHub.
git initThe git init command creates a new Git repository in the current project directory. This allows Git to begin tracking changes made to project files throughout the development process.
Initializing the repository at the beginning of the project ensures that all modifications can be committed, versioned, and pushed to GitHub.
After executing the command, Git displayed a message similar to:
Initialized empty Git repository in /path/to/wordpress-docker-lab/.git/
This confirms that the repository was successfully initialized.
Figure 2: Git repository initialized.
A local Git repository was successfully created, enabling version control for the project and preparing it for future commits and GitHub deployment.
Create the project files and directories required for the WordPress Docker Compose deployment and documentation.
touch README.md docker-compose.yml
The following files and directory were created:
README.md– Documents the project, deployment process, and outcomes.compose.yml– Defines the Docker Compose configuration for deploying the WordPress and MySQL services.screenshots/– Stores screenshots captured throughout the deployment process.
Creating these resources before deployment ensures that the project remains organized and that documentation is maintained alongside development.
The project structure was verified in Visual Studio Code, confirming that all required files and the screenshots directory were successfully created.
Figure 3: Project files in the Docker Compose project directory.
The project structure was successfully prepared, providing a well-organized workspace for the Docker Compose deployment and supporting documentation.
Create a Docker Compose configuration file to define and deploy the WordPress application and MySQL database as a multi-container environment.
Figure 4:
cat << 'EOF' > docker-compose.yml
services:
db:
image: mysql:8.0
restart: always
environment:
MYSQL_ROOT_PASSWORD: supersecretpassword
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpressuser
MYSQL_PASSWORD: wordpresspassword
volumes:
- db_data:/var/lib/mysql
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpressuser
WORDPRESS_DB_PASSWORD: wordpresspassword
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
volumes:
db_data:
wp_data:
EOFDeploy the WordPress and MySQL containers defined in the docker-compose.yml configuration file.
docker compose up -dThe docker compose up -d command reads the docker-compose.yml file and performs the following tasks:
- Pulls the required Docker images if they are not already available locally.
- Creates the Docker network for container communication.
- Creates the persistent Docker volumes (
db_dataandwp_data). - Creates the MySQL and WordPress containers.
- Starts both containers in detached mode (
-d), allowing them to run in the background.
The deployment completed successfully, and Docker created the required containers, network, and volumes without errors.
Figure 5: Running the Docker Compose application.
The WordPress application stack was successfully deployed using Docker Compose, with both the WordPress and MySQL services running as containers.
Verify that the WordPress and MySQL containers were successfully deployed and are running.
docker compose psThe docker compose ps command displays the status of all services managed by Docker Compose.
This command is used to confirm that:
- The WordPress container is running.
- The MySQL container is running.
- Both services started successfully after deployment.
The output displayed both containers with a status of Up, confirming that the deployment completed successfully.
Figure 6: Verifying that the Docker Compose services are running.
The WordPress and MySQL containers were successfully deployed and verified to be running, confirming that the Docker Compose configuration was functioning as expected.
Inspect the logs generated by the WordPress and MySQL containers to verify that both services started successfully and to identify any startup errors or warnings.
docker compose logs --tail 20The docker compose logs --tail 20 command displays the last 20 log entries from all services defined in the Docker Compose project.
Reviewing the logs helps to:
- Confirm that the WordPress container started successfully.
- Confirm that the MySQL database initialized successfully.
- Detect configuration issues or runtime errors.
- Verify communication between the WordPress and MySQL containers.
The --tail 20 option limits the output to the most recent log entries, making it easier to review the latest container activity.
The deployment was verified using both the Visual Studio Code terminal and Docker Desktop.
Visual Studio Code (CLI)
The following command was executed:
docker compose logs --tail 20The output confirmed that both the WordPress and MySQL containers started successfully without critical errors.
Docker Desktop (GUI)
The deployment was also verified using Docker Desktop by:
- Opening Docker Desktop.
- Navigating to Containers.
- Selecting the running WordPress and MySQL containers.
- Opening the Logs tab to review the container output.
The logs displayed in Docker Desktop matched the output produced by the Docker CLI, confirming that both services were operating correctly.
Figure 7: Docker Compose logs.
Figure 8: Container logs viewed in Docker Desktop.
Both the Docker CLI and Docker Desktop confirmed that the WordPress and MySQL containers initialized successfully and were operating as expected.
Stop and remove all containers, networks, and Docker volumes created during the deployment to return the environment to a clean state.
docker compose down -vThe docker compose down -v command stops and removes all containers, the Docker network, and the named Docker volumes created by the deployment.
Unlike docker compose down, which leaves the volumes intact, the -v option also removes:
db_datawp_data
Removing the volumes permanently deletes the MySQL database and WordPress application data, allowing the deployment to start from a completely fresh state during the next lab.
The cleanup was verified using both the Visual Studio Code terminal and Docker Desktop.
Visual Studio Code (CLI)
The following command was executed:
docker compose down -vThe terminal confirmed that the containers, network, and Docker volumes were successfully removed.
Docker Desktop (GUI)
Docker Desktop was opened to verify that:
- The WordPress container had been removed.
- The MySQL container had been removed.
- The Docker Compose application no longer appeared in the Containers view.
- The associated Docker volumes had been deleted.
Figure 09: Docker cli after cleaning up the Docker Compose application.
Figure 10: Docker Desktop after cleaning up the Docker Compose application.
The Docker Compose deployment and all associated resources, including the persistent Docker volumes, were successfully removed, restoring the environment to a clean state.
| Issue | Cause | Resolution |
|---|---|---|
| Docker images not found | Images had not been downloaded | Ran docker compose up -d to pull the required images. |
| Containers failed to start | Incorrect Docker Compose configuration | Reviewed and corrected the docker-compose.yml file. |
| Unable to access WordPress | Containers were still starting | Waited for the MySQL service to initialize before refreshing the browser. |
Through this project, I learned how to:
- Deploy a multi-container application using Docker Compose.
- Configure a WordPress application with a MySQL database.
- Create and manage Docker volumes for persistent storage.
- Inspect running containers and review container logs.
- Verify deployments using both the Docker CLI and Docker Desktop.
- Remove containers, networks, and volumes to restore a clean environment.
- Track project progress using Git before publishing to GitHub.
This project successfully demonstrated the deployment and management of a multi-container WordPress application using Docker Compose.
The deployment included container orchestration, persistent storage, service verification, log inspection, and complete environment cleanup. Throughout the project, Git was used for version control, and the completed solution was prepared for publication on GitHub as part of a Cloud and DevOps portfolio.
git add .git commit -m "Deploy WordPress using Docker Compose"git remote add origin https://github.com/samueleze1/wordpress-docker-lab.gitgit branch -M main
git push -u origin mainwordpress-docker-lab
│
├── docker-compose.yml
├── README.md
└── screenshots
├── 01-project-folder.png
├── 02-git-init.png
├── 03-project-files.png
├── 04-compose-file.png
├── 05-compose-up.png
├── 06-compose-ps.png
├── 07-compose-logs.png
├── 08-docker-desktop-logs.png
├── 09-compose-down.png
├── 10-docker-desktop-cleanup.png








