Frederik Witte
Frederik Witte

Reputation: 955

How can I link a container spawned by one compose file to a container which is spawned by another compose file?

Say that we have two compose files. Composefile "A" and "B".
They are both spawning containers.
One of the containers in composefile "A" needs to be linked with composefile "B".
How?

I have tried using external_links without luck.
Any suggestions would be appreciated.

Upvotes: 1

Views: 101

Answers (1)

Chris Tanner
Chris Tanner

Reputation: 1660

With the docker compose v2 syntax you can put them all on the same docker network by specifying the same default network in both docker compose files:

networks: default: external: name: myapp_net

It may give you a warning telling you the network doesn't exist in which case you just run the command it gives in the warning. After this containers from both compose files should be able to access each other.

There's an example of it working in one of my projects here.

Upvotes: 1

Related Questions