1. Home
  2. Docker
  3. Docker Tutorials
  4. Docker – Networking

Docker Networking

Docker provides an option to create and manage there own network for the networking between docker containers. Use docker network subcommand to manage the Docker networking.

Syntax:

docker network [options]

Use below tutorial to create, list and manage Docker networking.

List Docker Networks

Use ls option with docker network command to list currently available network on docker host.

docker network ls

Create Docker Network

Docker provides multiple types of network. Below command will create bridge network on your system.

Syntax:

docker network create -d [network_type] [network_name}

Example:

docker network create -d bridge my-bridge-network

Connect Container to Network

You can connect any container to existing docker network by using containers name or ID. Once the container connected to the network, it can communicate with other containers in the same network.

Syntax:

docker network connect [network_name] [container_name]

Example:

docker network connect my-bridge-network centos

Disconnect Container from Network

You can disconnect container from specific network any time using the following command.

Syntax:

docker network disconnect [network_name] [container_name]

Example:

docker network disconnect my-bridge-network centos

Inspect a Docker Network

Use inspect option with docker network comment to view the details of docker network

docker network inspect my-bridge-network

You will get the results like below.

Remove a Docker Network

Use rm option to remove any existing unused Docker network. You can specify one or more networks with space separated to remove.

Example:

docker network rm my-bridge-network network2 network3

You can also remove all unused networks from docker host using prune option.

docker network prune
Tags , ,
Was this article helpful to you? Yes 6 No