Docker Community Forums

Share and learn in the Docker community.

Network - container mode combined with bridge mode

docker network create --driver bridge alpine-net
docker run -dit --name alpine1 --network alpine-net alpine ash
docker run -dit --name alpine2 --network alpine-net alpine ash
docker run -dit --name alpine3 --network container:alpine2 alpine ash

My question is when I get into the container alpine1. Then, I ping the ip address of container alpine2 (172.19.0.3). How could the Docker daemon know whether I want to go to alpine2 or alpine3?

Aren’t both the container alpine2 and alpine3 share the same ip address (172.19.0.3)? How could Docker daemon know which one to route the traffic to?

docker exec -it alpine1 /bin/sh
/ # ping 172.19.0.3
PING 172.19.0.3 (172.19.0.3): 56 data bytes
64 bytes from 172.19.0.3: seq=0 ttl=64 time=0.075 ms
64 bytes from 172.19.0.3: seq=1 ttl=64 time=0.114 ms
64 bytes from 172.19.0.3: seq=2 ttl=64 time=0.103 ms

Hi :slight_smile:

No, all containers still have individual ips.

If you want to share a service, look into “docker service”
this way multiple containers can share load.