从外部docker-compose容器连接到docker容器 [英] Connecting to docker container from outside docker-compose container
问题描述
我们的两个服务
我们有LXV virtual-machine-1
,其中我们有docker-compose与 service-1
和其他服务。
我们还有另一个LXV virtual-machine-2
,其中我们有docker-compose与 service-B
和新的其他服务。假设这两个服务使用端口80和81
问题
如何从 service-1
到 service-B
在单独的LXV虚拟机中的单独docker组合中。
我们尝试了什么
我们在LXV virtual-machine-上更改了
,添加映射服务1和个主机
文件2 virtual-machine-1
的IP地址。 虚拟机-1
具有配置的转发代理,并将请求转发到 service-1
ping服务1
和 telnet服务1 80
$ c> virtual-machine-2 工作。
但是,在 virtual-machine-2
的docker-compose中,相同的ping无法在容器内工作。
service-B
IP映射的记录添加到主机
文件到 service中-1
容器主机
文件。 我们修改了start sh脚本来做到这一点。
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
.
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.
这篇关于从外部docker-compose容器连接到docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!