Philipp Wrann
Philipp Wrann

Reputation: 1849

docker-compose / extra_host pointing to different docker container on host-machine

The following setup:

I have "project A" set up with docker/docker-compose, that is a website. Then i have a different bundle - lets say "project B" set up with docker/docker-compose, that is a search-backend (elastic, etc).

Both are not composed in one file, so they dont know anything about eacht other.

Both containers/networks run locally (development). How do i add a hostname to a container in project A, that could request a container in project B?

i tried the "extra_host" option of docker-compose, but i dont know where to link my extra_host.

What i need is a bridge between 2 networks.

Upvotes: 0

Views: 275

Answers (1)

Al-waleed Shihadeh
Al-waleed Shihadeh

Reputation: 2855

if you are using docker-compose, you can assign the same network for both files and then you can reference them using the service name (you also need to create the network in this case)

docker-compose 1

version: '3.7'

networks:
  my-network:
    external: true

services:
  service-nr-1:
    image: MY-DOCKER-IMAGE
    environment:
      SERVICE-A: service-nr-2
    networks:
      - my-network

docker-compose 2

version: '3.7'

networks:
  my-network:
    external: true

services:
  service-nr-2:
    image: MY-DOCKER-IMAGE
    environment:
      SERVICE-A: service-nr-1
    networks:
      - my-network

Upvotes: 2

Related Questions