06. Docker Network
October 23, 2024About 1 min
Docker Network Mode
- bridge: setup ip for every container, and connect container to
docker0
network bridge. (Default mode) - host: The container will not virtualize it's own net, it share the ip and port with host.
- none: The container own its own network namespace, but there is no netowrk settings, such as veth pair, bridge connection, ip, etc.
Net Mode | Brief |
---|---|
bridge | Allocate IP and other resources for each container, and connect to docker virtual net bridge, default mode |
host | Container will not own it's onw net configuration, share with host |
none | Container has the independent Network namespace, but there is no network resources |
container | The new container will not create its own network configuration, only share with a specified container |
Info
Docker will create a bridge named docker0
, it connects to other physical or virtual net card, it can put all containers and local host to same physical network. Docker specify IP and mask for docker0 by default, which can make sure the communication between host and container.
Bridge
Example to test
docker run -d -p 8081:8080 --name test1 centos
docker run -d -p 8082:8080 --name test2 centos
Host
docker run -d -p 8083:8080 --network host --name test3 centos
Info
option -p 8083:8080
will not work
None
There is no network
docker run -d -p 8084:8080 --network none --name test4 centos
Container
docker run -d -p 8085:8080 --network container:test3 --name test5 centos
Warning
if shutdown the shared container, the new container will lost all network connection.
Network Operation
Default mode is bridge
- List
docker network ls
- Create
docker network create {newwork_name}
- Delete
docker network delete {network_name}
- Inspect
docker network inspect {network_name}