简体   繁体   中英

Docker Swarm + Docker Compose: running linked containers on different nodes?

I have an application I'm currently running on a single host via a Docker Compose file. The containers communicate with one another via a RabbitMQ container (so they're all linked). The app is starting to require more resources than my single host is able to provide, so I thought Docker Swarm would be ideal since I should be able to spin up the same set of containers via the same Compose file but on distributed nodes.

However, it appears that linked containers are constrained to reside on the same node, so setting up Docker Swarm on multiple nodes won't lead to the container distribution I'm looking for.

The Ambassador Pattern seems to be the recommended way to separate linked containers (by setting up proxies for the linked containers on each node), however I'm having trouble using it in a docker-compose file since the examples I've seen show setting up each node with docker run, then using the IP of the node running the shared service (RMQ in my case) to set an environment variable to tell the client's ambassador container where to route data for the linked service (as in https://docs.docker.com/engine/admin/ambassador_pattern_linking/ ). How can this be translated into a Compose file such that I don't need to know the IP that the service will be running on (since Docker Swarm will be deciding this after the Compose file is complete)?

Using links is deprecated . Instead, you can create a new network and add all your containers to that network:

$ docker network create myapp

Note that according to the Networking documentation for Compose , such a network is created automatically for your compose file.

This means that you shouldn't need to set up any links or networks at all, because Compose already creates a network automatically, and all containers should be reachable within that network using their container names.

Also have a look at Using Compose with Swarm for some limitations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM