[docker]网络-flannel

来源:互联网 发布:windows注册表详解 编辑:程序博客网 时间:2024/05/20 20:22
#!/usr/bin/env bash#https://www.ibm.com/developerworks/cn/linux/l-docker-network/index.html$ docker network lsNETWORK ID          NAME                DRIVER7fca4eb8c647        bridge              bridge9f904ee27bf5        none                nullcf03ee007fb4        host                host#bridge 网络表示所有 Docker 安装中都存在的 docker0 网络。除非使用 docker run --net=<NETWORK>选项另行指定,否则 Docker 守护进程默认情况下会将容器连接到此网络。在主机上使用 ifconfig命令,可以看到此网桥是主机的网络堆栈的一部分。#none 网络在一个特定于容器的网络堆栈上添加了一个容器。该容器缺少网络接口。#host 网络在主机网络堆栈上添加一个容器。您可以发现,容器中的网络配置与主机相同。## 创建自定义网络docker network create test-networkdocker inspect test-network |grep Subnetdocker network ls  #  --subnet、--gateway和 --ip-rangedocker run -itd --name=test1 --net=test-network radial/busyboxplus /bin/shdocker run -itd --name=test2 --net=test-network radial/busyboxplus /bin/shdocker exec -it test1 shpingdocker network rm  test-network# 静态链接bridges 自定义docker run -itd --name=test2 ppc64le/busybox /bin/sh#动态链接bridges 自定义docker run -itd --name=test2 ppc64le/busybox /bin/shdocker network connect test-network test2docker network inspect test-network#!/usr/bin/env bash# flannel原理: http://dockone.io/article/618SERVER_IP=`ifconfig eth0 | grep inet | grep netmask | grep -v "127.0.0.1" | awk '{print $2}'`yum install etcd -ysed -i 's#ETCD_LISTEN_CLIENT_URLS="http://localhost:2379"#ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"#g' /etc/etcd/etcd.confsystemctl restart etcd && systemctl enable etcdyum install flannel -ysed -i 's#FLANNEL_ETCD_ENDPOINTS="http://127.0.0.1:2379"#FLANNEL_ETCD_ENDPOINTS="http://'192.168.14.132':2379"#g' /etc/sysconfig/flanneldetcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'systemctl restart flanneld && systemctl enable flanneldsystemctl daemon-reloadsystemctl restart etcdsystemctl restart flanneldsystemctl restart dockerps -ef|grep dockeriptables -P FORWARD ACCEPTetcdctl rm --recursive /registry## docker加载/run/flannel/docker 配置#vim /usr/lib/systemd/system/docker.service.d/flannel.conf# vim /run/flannel/dockervim /usr/lib/systemd/system/docker.service  7 [Service]...  9 EnvironmentFile=-/run/flannel/docker... 13 ExecStart=/usr/bin/dockerd --log-level=error $DOCKER_NETWORK_OPTIONSps -ef|grep dockerroot       4655      1  3 19:08 ?        00:00:00 /usr/bin/dockerd --log-level=error --bip=172.17.92.1/24 --ip-masq=true --mtu=1472root       4659   4655  0 19:08 ?        00:00:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runcroot       4785   2791  0 19:08 pts/0    00:00:00 grep --color=auto dockerdocker run -it --rm radial/busyboxplus shdocker inspect fcce71e1b587|grep IPAddress