docker network create --driver macvlan --subnet=10.0.0.0/24 --gateway=10.0.0.254 -o parent=eth0 macvlan_1
ip link set eth0 promsic on (ubuntu或其他版本需要)
docker run -it --network macvlan_1 centos:6.9 /bin/bash
4. Docker 跨主机访问-overlay实现
docker run -d -p 8500:8500-h consul --name consul progrium/consul -server -bootstrap
consul:kv类型的存储数据库(key:value)
docker01、02上:
vim /etc/docker/daemon.json
{"hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"],"cluster-store":"consul://10.0.0.100:8500","cluster-advertise":"10.0.0.100:2376"}
vim /etc/docker/daemon.json
vim /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl restart docker
2)创建overlay网络
docker network create -d overlay --subnet 172.16.0.0/24--gateway 172.16.0.254 ol1
3)启动容器测试
docker run -it --network ol1 --name oldboy01 busybox /bin/bash
每个容器有两块网卡,eth0实现容器间的通讯,eth1实现容器访问外网