The network is visible in the docker container inspect $id output, where $id is the container id or container name. The name is listed under the NetworkSettings -> Networks section. That can be output with a format string:
You can use docker network connect $network_name $container_name to add a network to a container. And similarly, docker network disconnect $network_name $container_name will disconnect a container from a docker network.
Containers can ping each other by IP address if they are on the same docker network and you have not disabled ICC. If you are not on the default network named "bridge" you can use the included DNS discovery to ping and connect to containers by container name or network alias. Any new network you have created with docker network create $network_name has the DNS discovery turned on, even if it's using the bridge driver, it just needs to be separate from the one named "bridge". Containers can also connect over TCP ports, even without exposing or publishing ports in docker, as long as they are on the same docker network.
Here's a low level example of testing a network connection with netcat:
$ docker network create test-net
$ docker run --net test-net --name nc-server -d nicolaka/netshoot nc -vl 8080
17df24cf91d1cb785cfd0ecbe0282a67adbfe725af9a1169f0650a022899d816
$ docker run --net test-net --name nc-client -it --rm nicolaka/netshoot nc -vz nc-server 8080
Connection to nc-server 8080 port [tcp/http-alt] succeeded!
$ docker logs nc-server
Listening on [0.0.0.0] (family 0, port 8080)
Connection from nc-client.test-net 37144 received!
$ docker rm nc-server
nc-server
$ docker network rm test-net
Here in my case, it means that {container_name_1} and {container_name_2} are not on the same networks. (172.18 and 172.19 are not the same). To make them operate on the same network, on way is to use docker-compose. Follow this l
I required a quick test to validate what containers were connected to my custom bridge to troubleshoot a connectivity issue between containers. The below test can answer both the 1st & 3rd parts of the OP's question:
docker network inspect <tab complete to show avail. bridges> | grep IPv4Address
The results will reveal all the containers joined to the specified bridge by either IP or Name.
NOTE: Do not supply the random bridge names assigned to bridges in the output of ip addr list for the value of the bridge name in the above commands. If you do, the error Error: No such network: br-abtfta2nb624 will be puked.
As for the 2nd part of the OP's question, I refer the reader to @johnharris85 's excellent answer.
Old question.. but you are probably trying to make sure a cluster of containers are running the right network. There are two easy approaches. Your intuition may want something like: