There are majorly five networks in docker – bridge, host, overlay, none, and macvlan. Bridge network is the default network in docker. An introduction to these networks has been given in my previous article on docker architecture. In this article, I will show you the practical part of docker networking. You will get to know how you can check your docker network details, how to connect to a network, how to create your network, and more. So, let’s get started. Whenever you run a docker container, a default bridge network call docker0 gets associated with the container unless any other network is specified. For example, when I run ifconfig command, you will get the details of docker0 network of bridge type along with other network details.

Listing Network

Run the ls command to check all the networks running on the current host. You can see, seven networks are present currently including bridge, host and none which get created automatically when you install Docker. Depending on the containers I ran in the past, there are details of other custom networks also.

Inspecting Network

You can run inspect command to get all the details about a network type. It gives information about the network which includes Name, Id, Created time, Scope, Driver, Config details such as Subnet and Gateway address. I will also give container details if any container is up and running. Otherwise, it will return an empty string.

Create Network

Using create command, you can create your own you own network. You need to mention the driver type with –driver flag, in below example I am using bridge type. Run the ls command to check if the network got created. Now I will run a docker container on the network I have created. I am running a simple apache server container in below command. Running inspect command to check all the information of geekflare_network. You can find the container details this time in this inspect the output; the container name is determined_dubinsky.

Disconnect Network

To disconnect the network from the container, run the command below. You need to mention the network name and the container name in disconnect command. This network won’t be running determined_dubinsky container anymore; the container field will be empty. To create other than bridge network, you need to mention the driver name other than bridge. To create an overlay network, run the command below. To create a host network, mention host with –driver flag. The below example returns an error because only one host network instance is allowed, which was already running before. So, this command won’t create another host network.

Conclusion

That was all about docker networking and how you can connect, disconnect, create, inspect docker networks. Try out these commands to get familiar with Docket networking. If you are curious in learning Net Devops then check out this Udemy course.

Docker Networking 101 - 92Docker Networking 101 - 32Docker Networking 101 - 21Docker Networking 101 - 73Docker Networking 101 - 33Docker Networking 101 - 70Docker Networking 101 - 42Docker Networking 101 - 9Docker Networking 101 - 21Docker Networking 101 - 80Docker Networking 101 - 91Docker Networking 101 - 94Docker Networking 101 - 64Docker Networking 101 - 15Docker Networking 101 - 17Docker Networking 101 - 8Docker Networking 101 - 93Docker Networking 101 - 71Docker Networking 101 - 51Docker Networking 101 - 55Docker Networking 101 - 45Docker Networking 101 - 85Docker Networking 101 - 11