> For the complete documentation index, see [llms.txt](https://asafahmadov.gitbook.io/cloud-and-devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://asafahmadov.gitbook.io/cloud-and-devops/devops-bootcamp/containers-with-docker/docker-network.md).

# Docker Network

Docker takes care of the networking aspects so that the containers can communicate with other containers and also with the Docker Host. If you do an **ifconfig** on the Docker Host, you will see the Docker Ethernet adapter. This adapter is created when Docker is installed on the Docker Host.

![](https://www.tutorialspoint.com/docker/images/ifconfig.jpg)

This is a bridge between the Docker Host and the Linux Host. Now let’s look at some commands associated with networking in Docker.

### Listing All Docker Networks

This command can be used to list all the networks associated with Docker on the host.

```
docker network ls 
```

#### Return Value

The command will output all the networks on the Docker Host.

#### Example

```
sudo docker network ls
```

#### Output

The output of the above command is shown below

![](https://www.tutorialspoint.com/docker/images/docker_networks.jpg)

### Inspecting a Docker network

If you want to see more details on the network associated with Docker, you can use the Docker **network inspect** command.

```
docker network inspect networkname 
```

#### Options

* **networkname** − This is the name of the network you need to inspect.

#### Return Value

The command will output all the details about the network.

#### Example

```
sudo docker network inspect bridge 
```

#### Output

The output of the above command is shown below −

![Inspecting Docker Network](https://www.tutorialspoint.com/docker/images/inspecting_docker_network.jpg)

Now let’s run a container and see what happens when we inspect the network again. Let’s spin up an Ubuntu container with the following command −

```
sudo docker run –it ubuntu:latest /bin/bash 
```

![](https://www.tutorialspoint.com/docker/images/run_a_container_in_network.jpg)

Now if we inspect our network name via the following command, you will now see that the container is attached to the bridge.

```
sudo docker network inspect bridge
```

![](https://www.tutorialspoint.com/docker/images/container_attached_to_bridge.jpg)

### Creating Your Own New Network

One can create a network in Docker before launching containers. This can be done with the following command −

```
docker network create --driver drivername name 
```

#### Options

* **drivername** − This is the name used for the network driver.
* **name** − This is the name given to the network.

#### Return Value

The command will output the long ID for the new network.

#### Example

```
sudo docker network create --driver bridge new_nw 
```

#### Output

The output of the above command is shown below −

![](https://www.tutorialspoint.com/docker/images/long_id.jpg)

You can now attach the new network when launching the container. So let’s spin up an Ubuntu container with the following command −

```
sudo docker run –it –network=new_nw ubuntu:latest /bin/bash
```

![](https://www.tutorialspoint.com/docker/images/new_network.jpg)

And now when you inspect the network via the following command, you will see the container attached to the network.

```
sudo docker network inspect new_nw 
```

![](https://www.tutorialspoint.com/docker/images/new_nw.jpg)
