Docker network

1 Hostnetwork 

NETWORK: HOST

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.

NETWORK: BRIDGE

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>

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

https://docs.docker.com/network/network-tutorial-overlay/#walk-through

猜你喜欢

转载自www.cnblogs.com/anyu686/p/9091533.html