我想在另一个容器前面安装Nginx反向代理。这两个容器将使用以下命令位于相同的docker网络上:
docker network create my-net
现在,通常我可以检查容器所在的IP,然后在Nginx配置文件中使用它。我该怎么做才能做到无缝连接?这样我就可以使用单个docker-compose文件,并将两个容器都放在同一网络上,并正确配置Nginx。
谢谢
最佳答案
如果您使用docker-compose,则无需创建自己的网络,它将创建一个专用网络,该网络可以识别同一撰写文件中的所有其他服务。例如:
docker-compose.yml
version: '2'
services:
php:
image: php5.6
...<snip>...
nginx:
image: nginx:stable-alpine
ports:
- "443:443"
links:
- php
...<snip>...
然后在Nginx配置中:
proxy_pass http://php;
您无需在nginx compose块中指定用于网络的“链接”(它应该知道所有服务名称),但是它将有助于定义容器的加载顺序。
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
关于docker - NGINX作为另一个容器上的反向代理-如何配置配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38378635/