Docker network

2018/05/26 05:25
阅读数 25

1 Hostnetwork 


With the network set to host a container will share the host’s network stack and all interfaces from the host will be available to the container. The container’s hostname will match the hostname on the host system

Compared to the default bridge mode, the host mode gives significantly better networking performance since it uses the host’s native networking stack whereas the bridge has to go through one level of virtualization through the docker daemon. It is recommended to run containers in this mode when their networking performance is critical, for example, a production Load Balancer or a High Performance Web Server.


Isolated network within the host. With the network set to bridge a container will use docker’s default networking setup. A bridge is setup on the host, commonly named docker0, and a pair of veth interfaces will be created for the container. One side of the vethpair will remain on the host attached to the bridge while the other side of the pair will be placed inside the container’s namespaces in addition to the loopback interface. An IP address will be allocated for containers on the bridge’s network and traffic will be routed though this bridge to the container. Containers can talk to each other, and to talk to outside of the host, need to expose the port by docker run -p <exposed port of host>:<port of container> <container_name>

a bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network. 

Bridge networks apply to containers running on the same Docker daemon host.

A default bridge network cannot access container by hostname, you need create one by docker creat network my-network and docker run --name container-name -d --network mynetwork rabbitmq // to create your own network and assign container to it.

If you use docker-compose, the containers inside it will be in same network by defautl.

NETWORK: Overlay

overlay netwrok is designed for the comms between two containers on different host. 

To create overlay network 

docker network create -d overlay my-overlay

Start a service using the overlay network and publishing port 80 to port 8080 on the Docker host.

$ docker service create \
  --name my-nginx \
  --network my-overlay \ --replicas 1 \ --publish published=8080,target=80 \ nginx:latest

for muti host overlay network

0 收藏
0 评论
0 收藏