我有一个使用IP 172.10.100.17
在主机上运行的Docker EE。我已经使用默认参数安装了UCP,并且还部署了nginx容器,其主机端口443映射到容器上的443。
docker run -it --rm --name ucp -v /var/run/docker.sock:/var/run/docker.sock docker/ucp install --host-address 172.10.100.17 --interactive
docker run -it -d --name ngx -p 80:80 -p 443:443 nginx
https://172.10.100.17
? (注意:在nginx上启用了https)
最佳答案
The key is in the -p parameter, which handles port mapping. The first port listed is on the host, and the second is in the container.因此,-p 80:80意味着将主机上的端口80映射到容器中的端口80。
让我们将其扩展到Nginx。我假设您想同时使用HTTPS和UCP和Nginx。主机上每个端口只能监听一个应用程序。因此,如果两个容器都暴露了端口443,则可以使一个容器在主机上使用端口443(-p 443:443),而另一个容器使用其他端口(-p 4443:443)。然后,即使两个容器都暴露了端口443,您也将分别在主机的端口443和4443上访问它们-Docker正在进行端口转发。
您可能正在询问如何使用Nginx作为反向代理在单个端口上运行两个容器。尽管更复杂,但这也是可能的。
关于docker - Docker上的UCP和HTTP服务器共存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61692821/