简体   繁体   English

使用不同 docker-compose 配置构建的容器之间的可见性

[英]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.

相关问题 在不同的docker-compose之间共享容器 - Share containers between different docker-compose docker-compose 容器间连接 - docker-compose connection between containers docker-compose 在容器之间发出请求 - docker-compose make requests between containers docker-compose:容器之间没有连接 - docker-compose: no connection between containers 在以不同docker-compose文件描述且在不同docker-machines中运行的容器之间创建NFS共享 - Create a NFS share between containers described in different docker-compose files and running in different docker-machines Docker容器中的用户和文件权限配置(docker-compose版本3) - User and file permission configuration in Docker containers (docker-compose version 3) 使用 docker-compose 在 Docker 容器之间发送 RabbitMq 消息 - Sending RabbitMq messages between Docker containers using docker-compose Docker容器之间的JDBC连接(docker-compose) - JDBC connection between Docker containers (docker-compose) 使用 docker 运行或使用 docker-compose 运行的容器之间有什么区别吗? - Is there any difference between containers running with docker run or with docker-compose? 为什么“docker-compose”和“docker run”在不同的容器中运行 - Why does “docker-compose” and “docker run” run in different containers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM