I fired up two containers like this:
docker run -d -p 10001:80 --name blog1 tutum/wordpress
docker run -d -p 10002:80 --name blog2 tutum/wordpress
Then created a network:
docker network create my_network
Then connected my two containers to the network:
docker network connect my_network blog1
docker network connect my_network blog2
Then I fired up a third container and connected it to my network:
docker run -it --network my_network ubuntu:16.04 bash
I installed curl on the ubuntu container and tried to query the first 5 lines of blog1’s HTML:
curl -sSL blog1 | head -n5
I got this error:
curl: (7) Failed to connect to blog1 port 10001: Connection refused
Why did blog1 refuse the connection?
When I ran ‘docker network inspect my_network’ it shows all three containers on the same network:
[
{
"Name": "my_network",
"Id": "fd48da51d2da0fd5c5f9a9a879d4677d2b8bda9a7a33ca984a6a29efc9b01716",
"Created": "2021-03-18T16:30:37.3796504Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"710c502acd8e5535b99a7b7f9951ed768586c42b9b905833dee03a9829e912d0": {
"Name": "blog2",
"EndpointID": "86a766a6136e3b247a8991368c77d94a1fd63465128e7524e2735f3ec0f24575",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
},
"c22323fd24ddcfd0d871e53e755545323f2822dd1ab214f4a81862a971e88351": {
"Name": "romantic_payne",
"EndpointID": "2262bf054e5b74dc04a97e4e795d75a0148fc2a465828e6bd3c95ab8ea60629a",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
},
"d875536ede1182126d325290bdb01fc000b8a5e9944992f0b28f090cbc916ede": {
"Name": "blog1",
"EndpointID": "f783e8bd629d875f3125017faeae3ff59dd4c2e9c81b08452b41247f64856bd0",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]