If you now run the command docker network inspect isolated, you’ll see that the container has been attached ( Figure F).Īny other container you create on this network would be able to automatically connect to one another. To do this, the command would look like:ĭocker run -network=isolated -itd -name=docker-nginx nginx Say you’ve already pulled down the nginx image and want to launch a container, named docker-nginx, attached to the isolated network. Let’s attach a container to our newly created network. Once created, inspect the network, with the command docker network inspect new_subnet to see the results ( Figure E).įigure E Attaching a container to a networking The command for this would be:ĭocker network create -driver=bridge -subnet=192.168.2.0/24 -gateway=192.168.2.10 new_subnet Let’s say you want to create a network with a subnet of 192.168.2.0/24, a gateway of 192.168.2.10, and the name new_subnet. Run the inspect command on that newly created network with the command docker network inspect isolated to see that our new network has been automatically given its own subnet and gateway ( Figure D).īut what if you want to create a network with a specific subnet and gateway? That’s possible as well. The output of that command will be a long string of characters that represents the ID of that newly-created network ( Figure C). The creation of this network can be achieved with a single command:ĭocker network create -driver bridge isolated
I’m going to demonstrate how to create a bridge network and then show you how to deploy a container on that network. The output of that command would give you all the information you need about that network ( Figure B). If you want to view details on the bridge network, that command would be docker network inspect bridge. You can get more information on a particular network, by issuing the command docker network inspect NAME (Where NAME is the name of the network you want to view).
The above command will list out the Docker networks ( Figure A).
To view the current list of Docker networks, issue the command: Let’s see how we can manage those networks, create a new network, and then deploy a container on our new network.