Docker 提供三种 user-defined 网络驱动:bridge, overlay 和 macvlan。overlay 和 macvlan 用于创建跨主机的网络,
1 创建一个网络:
docker network create --driver bridge --subnet 172.19.1.0/16 --gateway 172.19.1.1 mynet2
2 查看创建的网络:
docker network ls
brctl show
3 创建一个容器,使用新建的网络
docker run -it --name my-busy --network=mynet2 busybox /bin/sh
======在容器里访问宿主机上起的http服务
1 起http服务:python -m SimpleHTTPServer 8000
2 因为宿主机有个ip是172.19.1.1,所以在容器里访问宿主机上的http服务:
wget http://172.19.1.1:8000/
发现有文件被下载下来了
参考资料:
https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587686&idx=1&sn=10f799f4b4c4a552871e751615b56880&chksm=8d3080ffba4709e9926d137a4cdb2a5907c96e0107481de297b071f3aabe37dbeeb0d34ef7d9&scene=21#wechat_redirect