Networking in docker
This is a study note from a tutorial video in YouTube: https://www.youtube.com/watch?v=fqMOX6JJhGo&t=4723s
There are three options of networks in docker. Bridge(default), host and none.
Bridge
docker run ubuntu
Bridge is the default network in docker.
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22172.17.0.3%22%20style%3D%22text%3Bhtml%3D1%3BstrokeColor%3Dnone%3BfillColor%3Dnone%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3BwhiteSpace%3Dwrap%3Brounded%3D0%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22380%22%20y%3D%22330%22%20width%3D%2240%22%20height%3D%2220%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E
In this mode, containers are isolated with the host. You can only use "run -p" to map to the host port to make it accessible.
You can create isolation in the docker network as well. In some cases, you may want certain containers connected through different bridge so that they can be isolated from other containers. By default, the docker will only create one bridge for all containers. But you can create a new bridge using below command.
docker network create --driver bridge --subnet 102.18.0.1/16 --gateway 102.18.0.1 custom-isolated-network
You can use docker run --network custom-isolated-network mysql:5.6 to run container in a specific network.
Host
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22172.17.0.3%22%20style%3D%22text%3Bhtml%3D1%3BstrokeColor%3Dnone%3BfillColor%3Dnone%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3BwhiteSpace%3Dwrap%3Brounded%3D0%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22380%22%20y%3D%22330%22%20width%3D%2240%22%20height%3D%2220%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E Web container can be associated with the host using below command:
docker run --network=host ubuntu
In this mode, some ports of host shared the same port numbers with containers, which means if the client access the port number 5000 on the host, it will automatically directed to the relevant containers.
None
docker run --network=none ubuntu
In none network mode, the containers are totally isolated from each other and the outside world. They can only run programs locally in their own containers.
Reference: https://www.youtube.com/watch?v=fqMOX6JJhGo&t=4723s
Comments
Post a Comment