I’ve been creating multiple docker-compose.yml file. I’m starting to have a long list of containers for each WordPress project that I create. Each time I create a new docker-compose.yml for each WordPress project, 2 containers are created (WordPress and a MySQL container).
What I want to achieve is this:
- A separate container for each WordPress environment.
- Have a single MySQL container that will be the centralization for all WordPress environments.
I’ve originally created a post about creating a docker-compose.yml for a WordPress dev environment. But that creates a WordPress + MySQL paired network and container setup.
Here’s an example of the solution I’ve created. Essentially, I’ve added an “external_links” section that references my dev DB called “db-mysql”
In my “docker-compose.yml”, under the WordPress service, I’ve added:
This will stop docker-compose from creating a new network. To learn more about it, click here to visit the official documentation from Docker.