jj-aa
jj-aa

Reputation: 1039

visibility between containers built with different docker-compose configuration

I need to use the service api_mysql in sass_php. Containers are built with different docker-compose.yml files and I understand they belong to different network and they can't see betweem them. 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":

$ 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

networks:
  api:

services:

  api_mysql:
    ...
    networks:
      api:

  api_php:
    ...
    depends_on:
      - api_mysql
    networks:
      api:

docker-compose-2.yml

version: '3'

networks:
  api:
  sass:

services:

  sass_mysql:
    ...
    networks:
      sass:

  sass_php:
    ...
    depends_on:
      - sass_mysql
    networks:
      api:
      sass:

Upvotes: 1

Views: 670

Answers (1)

Michée Lengronne
Michée Lengronne

Reputation: 789

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. It can access the ones in repo2_api network but this network is not used by api_mysql.

So to remediate, you can declare your network outside your docker-compose files and add it that way:

networks:
  default:
    external:
      name: my-pre-existing-network

Ref: 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.

I would prefer the first method.

Upvotes: 2

Related Questions