[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
*
Docker网络模式
Docker在创建容器时有四种网络模式:bridge/host/container,bridge为默认不需要用–net去指定,
其他三种模式需要在创建容器时使用–net去指定
<>单机模式
1.bridge模式(默认模式)
docker run时使用–net=bridge,这种模式会为每个容器分配一个独立的Network Namespace,
同一个宿主机上的所有容器会在同一个网段下,相互之间是可以通信的
注1:bridge为默认模式,不需要使用参数–net去指定,使用了–net参数反而无效
2.host模式
docker run时使用–net=host,容器将不会虚拟出IP/端口,而是使用宿主机的IP和端口
docker run -itd --net=host 注1:host模式不能使用端口映射和自定义路由规则,这些都与主机一致,-p 与-icc 参数是无效的
3.container模式(略,用的比较少)
4.none模式(略,用的比较少)
<>集群模式
5.跨主机通信(略)
以上四种均未跨主机,也就是说容器均运行在一台宿主机上,但实际生产环境不可能只用一台来跑。
肯定会用到多台,那么多台主机之间的容器如何通信
1.使用路由机制打通网络
2.使用Open vSwitch(OVS)打通网络
3.使用flannel来打通网络
4.使用Quagga来实现自动学习路由
*
外部访问docker容器
1.bridge模式
docker run -itd -p 7001:7001 镜像ID
<>-p参数可以出现多次,绑定多个端口号
docker run -itd -p 8080:8080 -p 8088:8088 镜像ID
当使用 -P 标记时,Docker 会随机映射一个 49000~49900 的端口到内部容器开放的网络端口
2.host模式
docker run -itd --net=host 镜像ID
注1:不需要添加-p参数,因为它使用的就是主机的IP和端口,添加-p参数后,反而会出现以下警告:
WARNING: Published ports are discarded when using host network mode
注2:宿主机的ip路由转发功能一定要打开,否则所创建的容器无法联网!
echo 1 > /proc/sys/net/ipv4/ip_forward
3.相关命令
#停止并删除所有容器
docker stop $(docker ps -aq) && docker rm $(docker ps -aq)
4.网桥查看工具bridge-utils
yum install bridge-utils
brctl show
*
创建自定义网络:(设置固定IP)
1.创建自定义网络
docker network create --subnet=172.18.0.0/16 mynetwork
<>查看网络配置
docker network ls
2.创建Docker容器
docker run -itd --name networkTest1 --net mynetwork --ip 172.18.0.2
centos:latest /bin/bash