Return to site

DEVOPS: docker network or how to bind container to a network

· devops

Docker networking allows you to attach a container to as many networks as you like.

You can also attach an already running container. 

Here, the basics to manipulate and create networks with docker:

𝐌𝐚𝐧𝐢𝐩𝐮𝐥𝐚𝐭𝐢𝐧𝐠 𝐧𝐞𝐭𝐰𝐨𝐫𝐤𝐬:

―Removing a network:❌

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑟𝑚 𝑀𝑦𝑂𝑣𝑒𝑟𝑙𝑎𝑦𝑁𝑒𝑡𝑤𝑜𝑟𝑘

―Listing networks:📃

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑙𝑠

―Getting information about a network:🕵️‍♂️

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑖𝑛𝑠𝑝𝑒𝑐𝑡 𝑀𝑦𝑂𝑣𝑒𝑟𝑙𝑎𝑦𝑁𝑒𝑡𝑤𝑜𝑟𝑘

―Connecting a running container to a network:🔌

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑐𝑜𝑛𝑛𝑒𝑐𝑡 𝑀𝑦𝑂𝑣𝑒𝑟𝑙𝑎𝑦𝑁𝑒𝑡𝑤𝑜𝑟𝑘 𝑛𝑔𝑖𝑛𝑥

―Connecting a container to a network when it starts:🔌

𝑑𝑜𝑐𝑘𝑒𝑟 𝑟𝑢𝑛 -𝑖𝑡 -𝑑 --𝑛𝑒𝑡𝑤𝑜𝑟𝑘=𝑀𝑦𝑂𝑣𝑒𝑟𝑙𝑎𝑦𝑁𝑒𝑡𝑤𝑜𝑟𝑘 𝑛𝑔𝑖𝑛𝑥

―Disconnecting a container from a network:❌🔌

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑑𝑖𝑠𝑐𝑜𝑛𝑛𝑒𝑐𝑡 𝑀𝑦𝑂𝑣𝑒𝑟𝑙𝑎𝑦𝑁𝑒𝑡𝑤𝑜𝑟𝑘 𝑛𝑔𝑖𝑛𝑥

𝐂𝐫𝐞𝐚𝐭𝐢𝐧𝐠 𝐧𝐞𝐭𝐰𝐨𝐫𝐤𝐬:⚙

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑐𝑟𝑒𝑎𝑡𝑒 -𝑑 𝑜𝑣𝑒𝑟𝑙𝑎𝑦 𝑀𝑦𝑂𝑣𝑒𝑟𝑙𝑎𝑦𝑁𝑒𝑡𝑤𝑜𝑟𝑘

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑐𝑟𝑒𝑎𝑡𝑒 -𝑑 𝑏𝑟𝑖𝑑𝑔𝑒 𝑀𝑦𝐵𝑟𝑖𝑑𝑔𝑒𝑁𝑒𝑡𝑤𝑜𝑟𝑘

𝑑𝑜𝑐𝑘𝑒𝑟 𝑛𝑒𝑡𝑤𝑜𝑟𝑘 𝑐𝑟𝑒𝑎𝑡𝑒 -𝑑 𝑜𝑣𝑒𝑟𝑙𝑎𝑦 \

 --𝑠𝑢𝑏𝑛𝑒𝑡=192.168.0.0/16 \

 --𝑠𝑢𝑏𝑛𝑒𝑡=192.170.0.0/16 \

 --𝑔𝑎𝑡𝑒𝑤𝑎𝑦=192.168.0.100 \

 --𝑔𝑎𝑡𝑒𝑤𝑎𝑦=192.170.0.100 \

 --𝑖𝑝-𝑟𝑎𝑛𝑔𝑒=192.168.1.0/24 \

 --𝑎𝑢𝑥-𝑎𝑑𝑑𝑟𝑒𝑠𝑠="𝑚𝑦-𝑟𝑜𝑢𝑡𝑒𝑟=192.168.1.5" \

 --𝑎𝑢𝑥-𝑎𝑑𝑑𝑟𝑒𝑠𝑠="𝑚𝑦-𝑠𝑤𝑖𝑡𝑐ℎ=192.168.1.6" \

 --𝑎𝑢𝑥-𝑎𝑑𝑑𝑟𝑒𝑠𝑠="𝑚𝑦-𝑝𝑟𝑖𝑛𝑡𝑒𝑟=192.170.1.5" \

 --𝑎𝑢𝑥-𝑎𝑑𝑑𝑟𝑒𝑠𝑠="𝑚𝑦-𝑛𝑎𝑠=192.170.1.6" \

 𝑀𝑦𝑂𝑣𝑒𝑟𝑙𝑎𝑦𝑁𝑒𝑡𝑤𝑜𝑟𝑘