services that want to use same ports

I think I'm thinking about this whole thing wrong. I posted two screenshots showing two seperate setups for two projects. Both use a nginx frontend (port 8080) and php-fpm backend (9000). Obviously I can't run both projects on the same ports, how could I go about running these two projects without messing up the networking? Or would I do something like host nginx for both projects in it's own service and the same for php-fpm? Kind of new to all this so still figuring it out
No description
No description
8 Replies
DJKnaeckebrot
DJKnaeckebrot3mo ago
You can run it at the same time. You just need to make sure that you are not using sth like ports: 8080:8080 but ports: 8080 This will make sure that you don’t map port 8080 on the container to your hosts port 8080 which would lead to port in use issues. The port you see in the domains tab shows which port on the container the proxy should Proxy to
jordans231
jordans231OP3mo ago
thanks bro you're right. i had no idea! coming back to this @DJKnaeckebrot I am actually getting issues. It works but at times when my host restarts or I deploy one of the containers again, it's almost as if they will try to bind to the port at the same time and one of the containers always breaks. so I have to stop one and do each one one at a time. I have restart: always. what would you advise?
DJKnaeckebrot
DJKnaeckebrot3mo ago
Would you mind sharing the details? 😄 without the compose files it’s though to help 😂
jordans231
jordans231OP3mo ago
@DJKnaeckebrot thanks haha here they are
No description
No description
No description
jordans231
jordans231OP3mo ago
as you can see they are all running. right now only two of the nginx containers (port 8080) can contact their respective php container running on port 9000. the last one is having issues.
No description
jordans231
jordans231OP3mo ago
I have three running at the same time in pairs of nginx -> php-fpm 8080 -> 9000
jordans231
jordans231OP3mo ago
Nevermind! Figured it out. I needed to change the name of the services to be unique since docker communicates through service name then the port. So I gave each services in the container a unique name and made my nginx config match the correct service name and voila! It all goes perfect.
No description
No description
No description
No description
jordans231
jordans231OP3mo ago
thanks for all your help anyways bro.

Did you find this page helpful?