docker四種網路模式區別
阿新 • • 發佈:2018-11-06
1.host模式
host表示容器共享宿主機的ip和埠號。容器中不會虛擬自己的網絡卡和ip,當你檢視容器ip的時候,其實是宿主機的ip。
如:建立nginx容器
docker run -tid --net=host --name nginx nginx:1.13.12
你訪問主機的http://ip:80其實就是容器的80埠,不用做埠映射了。
2.Container模式(未測試)
container是共享容器ip地址和埠
docker run -tid --net=container:nginx --name mysql mysql:5.7
3.None模式
使用none模式時容器沒有網絡卡、IP、路由等資訊。需要我們自己為Docker容器新增網絡卡、配置IP等
docker run -tid --net=none --name nginx2 nginx:1.13.12
4.bridge模式
bridge模式是docker預設的網路模式,這種模式容器直接可以互相通訊,但無法和宿主機通訊。
注:bridge不支援自定義容器ip
如: docker run -itd --net bridge --ip 172.18.0.10 nginx:latest /bin/bash
會報錯:
docker: Error response from daemon: User specified IP address is supported on user defined networks only.
跨主機通訊:
直接路由方式、橋接方式(如pipework)、Overlay隧道方式(如flannel、ovs+gre)