Locally, I use Docker and WSL2 for development. Inevitably I need to connect multiple docker compose apps, this blog post details how.
If I’m reading data from an API, I might use the public instance of an API. However, as soon as I need to create, update, or delete data, the public API doesn’t work, I switch to using a local instance.
Connect docker compose apps
Connecting multiple docker compose apps is simple as soon as you know how. I’m sure there are multiple ways to do it but the following works for me.
To ensure two or more docker compose apps can see each other, I ensure they use the same network, add the network to each of the docker-compose.yml files as below.
networks: default: name: costs.network external: true
Before you run each of the apps you will need to create the new network, the syntax to create a network is as below.
docker network create [network-name]
If you named your network costs.network
as per my example, you would create the network as below.
docker network create costs.network
Your apps will now be able to see each other, all you need now is the URI. The URI should be the service name, if you review the Costs to Expect API docker-compose.yml file, you will see that I have set the service name as costs.api.app, the URI to access the API is therefore http://costs.api.app.