Containers can not access each other without specfing the network or udner bridge network?

Hi, guys. I am new to docker and I am trying to resolve this question…

I know that the containers can access each other if I specify the network like:

docker run -dit --name ub1 --network but ubuntu
docker run -dit --name ub2 --network ubt ubuntu

So the command ping ub2 can work inside the container ub1.

But, if I did not specify the --network settings and I think the container is created under the network bridge or null?

Is that mean the containers are under the same network if I do not specify the --network settings? Apparently, ub3 can not access ub4 by container name… So why?

docker run -dit --name ub3 ubuntu
docker run -dit --name ub4 ubuntu

However, even if I specify the network under bridge, it still can not access each other by container name. Why?

docker run -dit --name ub5 --network bridge ubuntu
docker run -dit --name ub6 --network bridge ubuntu
$ docker exec -it ub8 /bin/bash
root@dc399b0c1b2e:/# ping ub5
ping: ub5: Name or service not known

Also, Is this correct:
docker0 = network bridge?

I hope this answers all your questions:
docker0 is connected to the default bridge network. The default bridge network has no build-in service discovery.

User defined networks provide dns-based service discovery for containers attached to the same network. A container can access a service of another container in the same network using its service name (on docker compose deployment) or container name (--name {container name}) and the container port of the service - there is no build-in way to allow specific ports and deny others.

One question though: why would you expect containers in different networks to reach each other?

Hi @meyay. Thanks for your reply and apologies for my late reply.

Oh, I see…
Probably because I typed the wrong network name…

It is supposed to be ubt for both containers bu1 and ub2

docker run -dit --name ub1 --network but ubuntu
docker run -dit --name ub2 --network ubt ubuntu
1 Like