How does docker handle requests forwarded by the host to various containers?

  docker, question

It was only a few days before docker was disturbed.

For example, I made a web server, nginx was placed in the host computer, and several php-fpm containers were built in docker. I intend to use nginx to forward to the containers for load balancing (testing, playing). Then I found that the forwarding address written in nginx configuration is not easy to write. Every time the container is restarted, a new ip will be automatically reassigned, and then the forwarding address I wrote in the host nginx configuration will go wrong. . .

I read a lot on the internet and said that I can make the container into a fixed ip, but all kinds of troubles, such as getting my own network card, are not perfect either. it is said that it will be redistributed after restarting and need to be executed again. . .

Do you have any good ideas and solutions?

Two methods:

  1. The php container uses -p to center the port to the host, and then nginx forwards to localhost:[ mapped port]

  2. Put nginx in container, link php container, and nginx forward to linkname:port