刚开始折腾docker没几天。
比如我做一个web服务器,nginx放在主机里,在docker里建了几个php-fpm的容器,打算用nginx转发到容器里做负载均衡(测试,搞着玩的)。然后发现,在nginx的配置里写的转发地址,不好写啊。每次重启容器,都会自动重新分配一个新的ip,那我在主机nginx配置里写的转发地址,就会出错。。。
在网上看了很多,都说可以把容器弄成固定ip的,但各种麻烦,要自己弄网卡之类的,而且也不完美,据说重启后也是会重新分配,还需要再执行一次。。。
大家有没有什么好的思路,求解答
Two methods:
The php container uses -p to shoot the port to the host, and then nginx forwards it to localhost:[mapped port]
Put nginx in the container, link the php container, and forward nginx to linkname:port
LZ seems to have to run nginx on the host. Here is something that can dynamically change upstream. Combined with
docker inspect
you can get it:https://github.com/yzprofile/...
You can get the IP with this command, and write an automated script to generate nginx config yourself