Under docker custom network: nginx in different containers access PHP projects through container names.

Scenario: Each service has its own set of running environment, and each has its own nginx; we use the Nginx project of container A to access the content of the nginx project under container B, and under a custom network

First we can customize a network: docker default bridge:

docker network create apollo_network

Then run your container and specify the network: (--network apollo_network parameter)

for example:

docker run -v E:\web\sheng\core\timetracker:/var/www/html -p 8181:8080 -d --network apollo_network --name apollo_core registry.git.asc-vision.de/sheng/apollo_core

docker run -v E:\web\sheng\tt\tm-timetracker:/var/www/html -p 8282:80 -d --network apollo_network --name apollo_timetracker_module  registry.git.asc-vision.de/sheng/apollo_timetracker_module

Then I access the second with the first:

Why record this? This is because the default port 80 of nginx I have been using before can be pinged when using the container name or IP, but the entry file for my nginx configuration PHP project is in the nginx default project file path (var/www/html) Under the public (index); a situation occurred: when curling the other party's container, it always accessed the root directory (var/www/html), but did not access (var/www/html/public), and the nginx configuration seemed to be lost. It didn't work, so I solved the problem by changing the port.

nginx configuration:

But today I did not find the reason why using 80 caused this problem...

Guess you like

Origin blog.csdn.net/wqzbxh/article/details/133301711