[英]visibility between containers built with different docker-compose configuration
I need to use the service api_mysql in sass_php .我需要在sass_php 中使用服务 api_mysql 。 Containers are built with different docker-compose.yml files and I understand they belong to different network and they can't see betweem them.容器是用不同的 docker-compose.yml 文件构建的,我知道它们属于不同的网络,它们之间看不到。 The following is my current configuration, but then when I want to use the service I get: "php_network_getaddresses: getaddrinfo failed: Name does not resolve":以下是我当前的配置,但是当我想使用我得到的服务时:“php_network_getaddresses: getaddrinfo failed: Name does not resolve”:
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
bcad56c87a8c repo1_api bridge local
196f42d7cbea repo2_api bridge local
79b41a714b48 repo2_sass bridge local
docker-compose-1.yml docker-compose-1.yml
networks:
api:
services:
api_mysql:
...
networks:
api:
api_php:
...
depends_on:
- api_mysql
networks:
api:
docker-compose-2.yml docker-compose-2.yml
version: '3'
networks:
api:
sass:
services:
sass_mysql:
...
networks:
sass:
sass_php:
...
depends_on:
- sass_mysql
networks:
api:
sass:
As they live in different networks so do their domain names.由于他们生活在不同的网络中,所以他们的域名也是如此。 The DNS used by sass_php
does not access the domain names available in repo1_api
network. sass_php 使用的sass_php
不访问repo1_api
网络中可用的域名。 It can access the ones in repo2_api
network but this network is not used by api_mysql
.它可以访问repo2_api
网络中的网络,但api_mysql
不使用该网络。
So to remediate, you can declare your network outside your docker-compose
files and add it that way:因此,要补救,您可以在docker-compose
文件之外声明您的网络并以这种方式添加:
networks:
default:
external:
name: my-pre-existing-network
Ref: https://docs.docker.com/compose/networking/#use-a-pre-existing-network参考: https://docs.docker.com/compose/networking/#use-a-pre-existing-network
Or you can EXPOSE
the api_mysql
ports to your localhost and access by it.或者您可以将EXPOSE
端口api_mysql
到您的本地主机并通过它访问。
I would prefer the first method.我更喜欢第一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.