Communication between multiple docker-compose projects Communication between multiple docker-compose projects docker docker

Communication between multiple docker-compose projects


You just need to make sure that the containers you want to talk to each other are on the same network. Networks are a first-class docker construct, and not specific to compose.

# front/docker-compose.ymlversion: '2'services:  front:    ...    networks:      - some-netnetworks:  some-net:    driver: bridge

...

# api/docker-compose.ymlversion: '2'services:  api:    ...    networks:      - front_some-netnetworks:  front_some-net:    external: true

Note: Your app’s network is given a name based on the “project name”, which is based on the name of the directory it lives in, in this case a prefix front_ was added

They can then talk to each other using the service name. From front you can do ping api and vice versa.


UPDATE: As of compose file version 3.5:

This now works:

version: "3.5"services:  proxy:    image: hello-world    ports:      - "80:80"    networks:      - proxynetnetworks:  proxynet:    name: custom_network

docker-compose up -d will join a network called 'custom_network'. If it doesn't exist, it will be created!

root@ubuntu-s-1vcpu-1gb-tor1-01:~# docker-compose up -dCreating network "custom_network" with the default driverCreating root_proxy_1 ... done

Now, you can do this:

version: "2"services:  web:    image: hello-world    networks:      - my-proxy-netnetworks:  my-proxy-net:    external:      name: custom_network

This will create a container that will be on the external network.

I can't find any reference in the docs yet but it works!


Just a small adittion to @johnharris85's great answer,when you are running a docker compose file, a "default" network is createdso you can just add it to the other compose file as an external network:

# front/docker-compose.yml version: '2'   services:       front_service:    ...

...

# api/docker-compose.ymlversion: '2'services:  api_service:    ...    networks:      - front_defaultnetworks:  front_default:    external: true

For me this approach was more suited because I did not own the first docker-compose file and wanted to communicate with it.