问题
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