Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker service discovery does not work with default bridge

Seems like docker service discovery just works with user defined networks and not with default bridge (docker0), but I didn't find anything in the docs.

docker run --rm -d --name c1 alpine sleep 2h
docker run --rm -d --name c2 alpine sleep 2h
docker exec -ti c1 ping c2

It gives me ping: bad address 'c2'

But if I create a custom bridge network everthing works fine:
docker network create u-bridge
docker run --rm -d --name u1 --net u-bridge alpine sleep 2h
docker run --rm -d --name u2 --net u-bridge alpine sleep 2h
docker exec -ti u1 ping u2

It gives me: PING u2 (172.18.0.3): 56 data bytes (...)

Shouldn't default bridge network have service discovery?

like image 505
Francisco Berrocal Avatar asked Mar 08 '23 19:03

Francisco Berrocal


1 Answers

Containers on the default bridge need to be explicitly linked, which is considered legacy/deprecated behaviour.

Warning: The --link flag is a deprecated legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link. One feature that user-defined networks do not support that you can do with --link is sharing environmental variables between containers. However, you can use other mechanisms such as volumes to share environment variables between containers in a more controlled way.

User defined networks should be used instead, as you have demonstrated.

like image 103
Matt Avatar answered Mar 10 '23 10:03

Matt