dockergoogle-cloud-platform

difference between docker BRIDGE and HOST driver?


Can you give me one guide or graph to understand the difference?

The reason why I ask this question is I can't open website with the following method:

docker network create -d bridge mybridge 
docker run -d --net mybridge --name db redis 
docker run -d --net mybridge -e DB=db -p 8000:5000 --name web chrch/web 

But I can open website with the following method:

docker run --rm -d --network host --name my_nginx nginx

I use google cloud platform VM instance and install docker by myself.


Solution

  • According to the docker documentation about bridge networking:

    In terms of Docker, a bridge network uses a software bridge which lets containers connected to the same bridge network communicate, while providing isolation from containers that aren't connected to that bridge network.

    According to the docker documentation about host networking

    If you use the host network mode for a container, that container's network stack isn't isolated from the Docker host (the container shares the host's networking namespace), and the container doesn't get its own IP-address allocated. For instance, if you run a container which binds to port 80 and you use host networking, the container's application is available on port 80 on the host's IP address.

    If you want to deploy multiple containers connected between them with a private internal network use bridge networking. If you want to deploy a container connected to the same network stack as the host (and access the same networks as the host) use host networking. If you simply want to publish some ports, run the container with the --publish or -p option, such as -p 8080:80.