Connecting to docker container from outside docker-compose container

不羁的心 提交于 2019-12-11 15:26:09

问题


Our two services

We have LXV virtual-machine-1 where we have docker-compose with service-1 and other services. We have another LXV virtual-machine-2 where we have docker-compose with service-B and new other services. Let's assume these two services use ports 80 and 81

Question

How to connect from service-1 to service-B in separate docker compositions in separate LXV virtual machines.

What we tried

We changed hosts file on LXV virtual-machine-2 by adding mapping service-1 and ip address of virtual-machine-1. virtual-machine-1 has a forward proxy which is configured and forwards requests to service-1

ping service-1 and telnet service-1 80 from virtual-machine-2 work. However, same ping does not work inside the container in docker-compose of virtual-machine-2.


回答1:


As it turns out, docker container has default hosts file. So we needed to add a record of service-B IP mapping into hosts file into service-1 container hosts file. We modified starting sh script to do so.



来源:https://stackoverflow.com/questions/57092753/connecting-to-docker-container-from-outside-docker-compose-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!