sudo docker network create test1
a2aa9ca4bf3a67ee2524cab149b939e514dabc8a5b106868843829a1c5c5c4ef
sudo docker network create test2 --driver bridge
a7fc8f3d65367a64a7c2403b70f5c0f48c2888cf231ab5c8079df7f5ab003f7b
sudo docker network ls | grep test[12]
a2aa9ca4bf3a test1 bridge local
a7fc8f3d6536 test2 bridge local
sudo docker run --detach --name test-container --network test1 nginx:alpine
4893ce5f20cbe5b475542126c03576518b33dc2e63e55a717fc7f9e6c1f56e46
sudo docker exec test-container ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:12:00:02
inet addr:172.18.0.2 Bcast:172.18.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6300 (6.1 KiB) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
sudo docker network connect test2 test-container
sudo docker exec test-container ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:12:00:02
inet addr:172.18.0.2 Bcast:172.18.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:48 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6671 (6.5 KiB) TX bytes:0 (0.0 B)
eth1 Link encap:Ethernet HWaddr 02:42:AC:14:00:02
inet addr:172.20.0.2 Bcast:172.20.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5409 (5.2 KiB) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
sudo docker inspect test-container | grep Networks -A30
"Networks": {
"test1": {
<...>
"NetworkID": "a2aa9ca4bf3a67ee2524cab149b939e514dabc8a5b106868843829a1c5c5c4ef",
"EndpointID": "7063c7f3b28b4598b944164947a18a2d4f2d4b876d0e35d7f3d28b5253c1ae97",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.2",
<...>
"test2": {
<...>
"NetworkID": "a7fc8f3d65367a64a7c2403b70f5c0f48c2888cf231ab5c8079df7f5ab003f7b",
"EndpointID": "ff2125890ead9b518be631772cd51cccbc8d9f291841541d4cd2d25f2e722b2d",
"Gateway": "172.20.0.1",
"IPAddress": "172.20.0.2",
<...>
No comments:
Post a Comment