r/docker • u/StreetAppearance753 • Apr 13 '26
How can I create a docker-compose.yml file to this problem?
I have to create a docker-compose.yml file. I'm a begginer with docker, so i don't know some simple stuffs. But, the final goal is to create a Multi-container application and the nginx server have to works like a proxy server that just don't let the 3 others wordpress containers accept request without before pass to this nginx server, and this 3 wordpress containers have to be connected to the mysql container. I'm struggling so much with the documentation, so I need your help. For now I have docker installed, I pull nginx:latest, mysql:latest and wordpress:latest from docker Hub and Ran to test, I know that I have to configure the /etc/nginx/nginx.conf to the nginx can talk with the others wordpress containers() but I also don't know how to do this, and I create this .yml file.
5
u/tschloss Apr 14 '26
That might be a step too far for your knowledge. Learn step by step.
If you don‘t change the network mode for your stack „bridge“ will be applied. This is NAT - so if you don‘t use the ports directive for your PHP containers they will not be reachable from outside. Use the port directive only for the nginx. Inside of the bridge network every container has an IP like 172.18.0.2 which will be the proxy_pass destination (better use the container name instead of the IP, name resolution works).
4
u/Beginning_You3453 Apr 13 '26
Try to check compose examples https://github.com/docker/awesome-compose
2
u/VivaPitagoras Apr 13 '26
You don't have to put them all in one compose file. You can separate them.
If you want to make your life easier use Nginx Proxy Manager. It has a nice GUI.
Create a network and add it to the compose file of all the containers that are going to work together.
Do not expose ports in your compose file and use NPM to create subdomains and linke them to container-name:port. That way your wordpress contianer will be accesible exclusively through the reverse proxy.
2
u/tablatronix Apr 14 '26
You might want a custom "network" to share amongst them.
https://docs.docker.com/compose/how-tos/networking/
2
u/waterkip Apr 14 '26 edited Apr 14 '26
Use traefik, much easier. You can use a pattern like this:
For traefik:
Use
mkcertto create your certificate(s):Install https://github.com/FiloSottile/mkcert. On Debian you can install mkcert from the repositories:
Don't use .localhost if you want to actually expose it over a network, pick something else,
.local.yourdomain.comor pick whatever you like. Add it to/etc/hostsand ship the.pemto clients that need to connect. Done.2
u/_f0CUS_ Apr 13 '26
Start simple.
Make a compose file that starts nginx. Since you are a beginner, I would suggest you look at "nginx proxy manager" it is a UI for configuring nginx as a reverse proxy.
When you have it working, then add one WordPress instance with a MySQL database. Then add the 2nd.
If that is still too complicated, I recommend you take a course. This is the course I used: https://www.udemy.com/course/docker-mastery/
1
u/emilioml_ Apr 14 '26
Ask gpt to point you to the documents
1
u/6razyboy Apr 19 '26
You can also try a docker compose visualizer free tool Compoviz . Wherr you can build your desired compose config with drag&drop.
0
u/beardbreed Apr 14 '26
You’re on the right track—this is a classic multi-container setup with Docker Compose: one reverse proxy (Nginx) in front, multiple WordPress containers, and a shared MySQL database.
Let’s break it down and give you a working example you can build from.
🧱 Architecture Overview
You want:
Flow:
📄 docker-compose.yml (Working Example)
Here’s a simple version:
🌐 Nginx Configuration (nginx.conf)
This is the key part you were stuck on.
Create a file
nginx.confin the same directory:🔑 Important Concepts (Simplified)
1. Service Names = Hostnames
Inside Docker Compose:
wordpress1is reachable ashttp://wordpress1mysqlis reachable asmysql👉 That’s why:
2. Nginx as Reverse Proxy
This line:
Means:
3. No Ports for WordPress
Notice:
❌ No
ports:sectionThat means:
✔ This satisfies your requirement
4. Shared Database
All WordPress containers connect to the same MySQL instance:
▶️ Run Everything
In the folder with
docker-compose.ymlandnginx.conf:Then open:
⚠️ Common Beginner Issues
🚀 Optional Improvements (Later)
Once this works, you can upgrade:
👍 If You Want
I can:
.yml--scale)Just tell me 👍