Docker Compose:将Docker容器内的localhost:80端口转发到主机的80端口

3
我有一个情况:需要让由docker-compose 1.16.1协同管理的单个docker容器内的几个作业与遗留系统通信。遗留系统在同一主机上以vagrant box运行,并绑定到三个端口(7880、58608和58709)。我知道docker的默认配置允许将主机访问为172.17.0.1,但由于网络差异的晦涩技术原因,我需要“localhost”上的主机端口可用。那么,我该如何使在docker容器内从“localhost端口7880”(按)可见到主机端口7880?我完全控制docker实例和调用。

localhost resolves to the loopback address (127.0.0.1) of the container itself. Changing this might brake things. Have you considered any other option? For example adding an entry to your /etc/hosts, something like 172.17.0.1 my_docker_host... You will then access your legacy system at my_docker_host:7880 - tgogos
1个回答

2
只需在您的docker-compose文件中添加network_mode: host部分,即可与容器和主机共享localhost。

1
谢谢。显然,我在一段时间前学习Docker网络时错过了这个配置要点。 - Thorbjørn Ravn Andersen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接