docker 怎么在主机转发请求到各个容器里进行处理?
大家讲道理
大家讲道理 2017-04-25 09:01:25
0
3
677

刚开始折腾docker没几天。

比如我做一个web服务器,nginx放在主机里,在docker里建了几个php-fpm的容器,打算用nginx转发到容器里做负载均衡(测试,搞着玩的)。然后发现,在nginx的配置里写的转发地址,不好写啊。每次重启容器,都会自动重新分配一个新的ip,那我在主机nginx配置里写的转发地址,就会出错。。。

在网上看了很多,都说可以把容器弄成固定ip的,但各种麻烦,要自己弄网卡之类的,而且也不完美,据说重启后也是会重新分配,还需要再执行一次。。。

大家有没有什么好的思路,求解答

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
阿神

Two methods:

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

  2. 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/...

Ty80
docker inspect --format='{{.NetworkSettings.IPAddress}}' [CONTAINER_ID]

You can get the IP with this command, and write an automated script to generate nginx config yourself

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template