Container Dockers, Docker Networks, Compose Networks - how we should now β€œbind” containers

I have an existing application consisting of 4 docker containers running on the same host. They are linked by the link command.

However, after some docker updates, the link behavior has been deprecated and changed. We have problems when containers lose contact with each other.

So, docker says to use the new Network function on top of link ed containers. But I do not see how it works.

If 2 containers are on the same network, then the same ENV vars are automatically displayed on the containers, as if they were connected?

Or is the host file updated with the correct container name / IP addresses? Even after docker restart ?

I do not see in the documents how the container can find the location of another on its network?

In addition, compose seems to have a simple configuration for container binding and can automate some of them - would this be a way to go about defining multi-container applications? Or is it too early to put it into production?

Does compose support multiple host configurations?

at some point in the future we will probably need to transfer one of the containers to another host ....

+6
source share
1 answer

If 2 containers are on the same network, do the same ENV vars automatically appear on the containers, as if they were connected?

no, now you will need to use the container names as their host names. The new network function does not know which ports will be used. Think about it, since 2 computers are connected to the same network hub. Both can access the other by their host name.

Is the hosts file updated with the correct container name / IP addresses? Even after docker reboot?

yes, /etc/hosts files for all containers that are part of the network will be updated in real time by the docker engine.

I do not see in the documents how the container can find the location of another on its network?

Using the container name. See the Connect Containers section in the Working with doc network commands section: After connecting, the containers can communicate using a different IP address or container name.

In addition, the layout looks like a simple setup for linking containers and can automate some of them - will the way work for defining multiple container applications? Or is it too early to put it into production?

Compose supports the new networking feature as beta by offering the --x-networking option. You should not use it in the manufacturing process (current version of Compose 1.5).

In addition, the current implementation is a little inconvenient, since we must use the fully qualified name of the container, consisting of the project name + _ + container name + _1 . The documentation says that the next version (current version 1.5) will improve this so that we don’t have to worry about the project name for the container address.

Does the configuration support multiple hosts as well?

Yes, in conjunction with Swarm, as described in the overlay network documentation

+3
source

All Articles