Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed docker images.
In this blog post, we will discuss docker network. We will also create a bridge network and connect our existing docker container to it.
Prerequisite for this demo:
- One AWS EC2 instance with Linux 2 AMI and internet access.
What is docker network?
Docker network serves as the backbone of docker for communication between host, containers and remote. Docker’s networking subsystem is pluggable, using drivers. Several drivers exist by default and provide core networking functionality.
Docker network driver types:
- bridge: The default network driver. If you don’t specify a driver, this is the type of network you are creating. Bridge networks are usually used when your applications run in standalone containers that need to communicate.
- host: For standalone containers, remove network isolation between the container and the Docker host, and use the host’s networking directly. host is only available for swarm services on Docker 17.06 and higher.
- overlay: Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other. You can also use overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different Docker daemons. This strategy removes the need to do OS-level routing between these containers.
- macvlan: Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker daemon routes traffic to containers by their MAC addresses. Using the macvlan driver is sometimes the best choice when dealing with legacy applications that expect to be directly connected to the physical network, rather than routed through the Docker host’s network stack.
- none: For this container, disable all networking. Usually used in conjunction with a custom network driver. none is not available for swarm services.
- third-party network plugins: You can install and use third-party network plugins with Docker. These plugins are available from Docker Hub or from third-party vendors.
Network driver available by default: You can list network drivers available by default using docker network ls command.
Docker Network Demo:
## Docker: Network Management
## docker network [COMMAND]
## Create a network
## docker network create <network_name>
docker network create myBRIDGENETWORK
## List networks
## docker network ls
docker network ls -f "driver=bridge"
## Display detailed information on one or more networks
## docker network inspect <network_name or network_id>
docker network inspect myBRIDGENETWORK
## Connect a container to a network
## docker network connect <network_name> <container_name>
## docker container run --name myWEBSERVER --publish 80:80 --detach httpd #create the container if not created already
docker network connect myBRIDGENETWORK myWEBSERVER
## Disconnect a container from a network
## docker network disconnect <network_name> <container_name>
docker network disconnect myBRIDGENETWORK myWEBSERVER
## Remove all unused networks
docker network prune
## press N
## Remove one or more networks
## docker network rm <network_name>
docker network rm myBRIDGENETWORK
Hope you have enjoyed this article. In the next blog post, we will discuss docker volume.
To get more details on docker, please refer below docker documentation