Docker Networking
If you run ifconfig on the Docker Host, you’ll see the Docker Ethernet adapter. It takes care of networking so that containers can talk to each other and with the Docker Host. When Docker is installed, this adapter is created.

In Docker, networking is handled by the Docker Host and the Linux Host. Let’s look at some commands related to networking.
Docker Networks List
You can use this command to list all the Docker networks.
Syntax
$ docker network ls Options
None
Return Value
This command will show you all the networks on the Docker host.
Example
$ sudo docker network lsOutput
The output of the above command is shown below

Docker network inspection
Use Docker network inspect to see more details about Docker’s network.
Syntax
$ docker network inspect networkname Options
networkname − The network name you need to inspect.
Return Value
You’ll get all the info about the network with this command.
Example
$ sudo docker network inspect bridge
Output
The output of the above command is shown below

Spin up an Ubuntu container and let’s see what happens when we inspect the network again.
$ sudo docker run –it ubuntu:latest /bin/bash We can now see that the container is attached to the bridge by inspecting our network name.
$ sudo docker network inspect bridge
Creating your own network
The following command can be used to create a network in Docker before launching containers.
Syntax
$ docker network create --driver drivername name Options
drivername − The network driver’s name.
name − The network’s name.
Return Value
It’ll output the new network’s long ID.
Example
$ sudo docker network create --driver bridge sample
Output
The output of the above command is shown below

The new network can now be attached to the container when you launch it. Here’s how to spin up an Ubuntu container.
$ sudo docker run –it –network=new_nw ubuntu:latest /bin/bash