![](/img/trans.png)
[英]How to map a docker containers directory to the host with docker-compose?
[英]docker-compose: how to map few ip to few containers
我有一台具有两个IP地址的主机,也有两个Nginx容器。 如何将第一个IP映射到第一个Nginx,然后将第二个IP映射到第二个Nginx?
我假设IP实际上是一个套接字,例如,您的nginx1
容器将侦听端口8080上的IP地址#1(例如1.2.3.1
),而您的nginx2
容器将侦听您的IP地址2(例如, 1.2.3.2
)在端口8081上。
选项--publish
将满足您的需求。 它与docker run
一起使用,如下所示:
docker run -d --publish=1.2.3.1:8080:80 -name nginx1 nginx
此命令将在后台模式下将图像nginx
作为名为nginx1
的容器nginx1
,并且套接字1.2.3.1:8080
将绑定到容器的端口80
。 至于nginx2
: nginx2
docker run -d --publish=1.2.3.2:8081:80 -name nginx2 nginx
。
要将其与docker compose
结合使用,您只需要在.yml
文件中添加这些选项,就可以完成!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.