Docker allows servers from multiple containers to connect to each other via links and service discovery. However, from what I can see this service discovery is host-local. I would like to implement a service that uses other services hosted on a different machine.
There have been several approaches to solving this problem in Docker, such as CoreOS's jumpers
, host-local services that essentially proxy to the other machine, and a whole bunch of github projects for managing Docker deployments that appear to have attempted to support this use-case.
Given the pace of development it is hard to follow what current best practices are. Therefore my question is essentially:
- What (if any) is the current predominant method for linking across hosts in Docker, and
- Are there any plans for supporting this functionality directly in the Docker system?
Update
Docker 1.12 contains the so called swarm mode and also adds a
service
abstraction. They probably aren't mature enough for every use case, but I suggest you to keep them under observation. The swarm mode at least helps in a multi-host setup, which doesn't necessarily make linking easier. The Docker-internal DNS server (since 1.11) should help you to access container names, if they are well-known - meaning that the generated names in a Swarm context won't be so easy to address.With the Docker 1.9 release you'll get built in multi host networking. They also provide an example script to easily provision a working cluster.
You'll need a K/V store (e.g. Consul) which allows to share state across the different Docker engines on every host. Every Docker engine need to be configured with that K/V store and you can then use Swarm to connect your hosts.
Then you create a new overlay network like this:
Containers can now be run with the network name as run parameter:
They can also be connected to a network when already running:
More details are available in the documentation.
Seems like docker swarm
1.14
allows you to:assing hostname to container, using
--hostname
tag, but i haven't been able to make it work, containers are not able to ping each other by assigned hostnames.assigning services to machine using
--constraint 'node.hostname == <host>'