How to create custom network with specific subnet and IP range


Create a custom network with default bridge driver named as my-custom-net with subnet gateway and IP range
Create a container named as net-test with custom network i.e my-custom-net.
Inspect the container net-test and check the IP address assigned to it.

1. Create a custom network with custom IP settings.

#docker network create --subnet --gateway --ip-range --driver bridge --label host2net my-custom-net                             

2. Inspect the custom network.

#docker network inspect my-custom-net                                                           

Check the Subnet, Gateway, IP Range and Label assigned to the network.

3. Launch the container with the custom network.  

#docker run -itd --name test1 --net my-custom-net centos:centos7 bash             

4. check container IP with docker inspect command.

#docker container inspect test1| grep -w "IPAddress"                                         

No comments:

Post a Comment