This example project demonstrates how to configure Traefik with Docker to run a WordPress website, MySQL database, and Adminer for database management. It also includes the setup of local SSL certificates using the mkcert library for secure communication.
Before getting started with this project, make sure you have the following tools and software installed:
- Clone this repository to your local machine.
git clone https://github.com/reibengu/traefik-docker-wordpress.git
cd traefik-docker-wordpress
- Generate local SSL certificates using mkcert. This step will provide you with SSL certificates for your local development environment.
mkcert -install
mkcert -cert-file ./certs/local-cert.pem -key-file ./certs/local-key.pem traefik.test "*.traefik.test"
- Update the
/etc/hosts
file. To map the configured domains to your local machine's IP address, you'll need to add entries to your/etc/hosts
file. Open a terminal and run the following command to edit the file:
sudo nano /etc/hosts
Add the following entries to the file, associating each domain with your local IP address:
127.0.0.1 monitor.traefik.test
127.0.0.1 traefik.test
127.0.0.1 blog.traefik.test
127.0.0.1 db-admin.traefik.test
- Start the services using Docker Compose.
docker-compose up -d
This will launch Traefik, WordPress, MySQL, and Adminer containers. Traefik will automatically generate and manage SSL certificates for your services.
- Access your services using the custom domains in your browser:
- Traefik Dashboard: https://monitor.traefik.test
- Whoami: https://traefik.test
- Adminer (Database management): https://db-admin.traefik.test (MYSQL_ROOT_PASSWORD: test)
- WordPress: https://blog.traefik.test
You can access the individual containers directly for debugging or management purposes:
- WordPress Container:
docker exec -it traefik-blog-1 bash
- MySQL Container:
docker exec -it traefik-db-1 bash
This project is intended for local development purposes and may not be suitable for production use. Please ensure that you implement proper security measures, such as securing sensitive data and using real SSL certificates, when deploying to a production environment.
If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository.
Happy coding!