How do I create a docker-compose.yml file for a multi-container setup with Nginx and WordPress?

April 10, 2026 3 answers
Asked by FolioFold
I'm trying to put together a docker-compose.yml file for a multi-container application, but I'm fairly new to Docker and it's been tough to figure out. My goal is to set up an Nginx server to act as a reverse proxy for three WordPress containers, which should all connect to a MySQL database container. I've already installed Docker and pulled the latest images for Nginx, MySQL, and WordPress from Docker Hub. However, I'm not quite sure how to write the .yml file or configure the nginx.conf file so that the Nginx server routes requests to the WordPress containers correctly. Any guidance would be greatly appreciated!

Answers

TERRAIN MODEL
For a more user-friendly approach, consider using Nginx Proxy Manager. It provides a graphical interface for managing reverse proxy settings without diving too deep into the command line just yet. Start there, and once you get the hang of it, you can tackle the docker-compose.yml file step by step. Remember: it's okay to start simple and add complexity as you get more comfortable!
Reply to this answer
drafting compass
You're definitely on the right track for a classic multi-container setup! You'll want to create a docker-compose.yml file that defines your services: Nginx, three WordPress instances, and one MySQL database. Here's a simple layout to start with: ```yaml version: "3.9" services: nginx: image: nginx:latest container_name: nginx ports: - "80:80" volumes: - ./nginx.conf:/etc/nginx/nginx.conf depends_on: - wordpress1 - wordpress2 - wordpress3 networks: - wp-network mysql: image: mysql:latest container_name: mysql environment: MYSQL_ROOT_PASSWORD: rootpass MYSQL_DATABASE: wordpress networks: - wp-network wordpress1: image: wordpress:latest container_name: wordpress1 environment: WORDPRESS_DB_HOST: mysql:3306 WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: rootpass WORDPRESS_DB_NAME: wordpress networks: - wp-network wordpress2: image: wordpress:latest container_name: wordpress2 environment: WORDPRESS_DB_HOST: mysql:3306 WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: rootpass WORDPRESS_DB_NAME: wordpress networks: - wp-network wordpress3: image: wordpress:latest container_name: wordpress3 environment: WORDPRESS_DB_HOST: mysql:3306 WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: rootpass WORDPRESS_DB_NAME: wordpress networks: - wp-network networks: wp-network: ``` Also, don't forget to set up your nginx.conf correctly to ensure it can route traffic to your WordPress containers. That way, all requests will go through Nginx first. Good luck!

8 left turns: Make sure to double-check the service names in your configuration! Sometimes it's easy to get mixed up, especially when you're just starting out.

Reply to this answer
cabin pressure
If you're really stuck, focusing on one service at a time can help. Get Nginx running first, then add a single WordPress instance with its MySQL database. Once you've got that working, scale up to two or three WordPress instances. You might also find value in watching some online tutorials or taking a beginner course on Dockerโ€”it can really help clear things up!
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions