第八周 周三
早 回顾
registry 创建仓库
-
启动docker
-
拉取镜像
docker pull registry
-
启动镜像,同时挂载目录(保存镜像)端口映射5000
[root@docker ~]# docker run -d -v /regist/:/var/lib/registry/ -p5000:5000 registry:latest
-
修改/etc/dovker/daemon.json key.
, "insecure-registries":[ "http://192.168.1.22:5000" ] #在配置文件中加入
-
重启docker
[root@docker ~]# systemctl restart docker
-
测试访问仓库信息
[root@docker ~]# curl 192.168.1.22:5000/v2/_catalog
-
上传
[root@docker ~]# docker tag centos:latest 192.168.1.22:5000/abc:v0 #打标签 [root@docker ~]# docker push 192.168.1.22:5000/abc:v0 #上传
-
下载
[root@node1 ~]# docker pull 192.168.1.22:5000/abc:v0
docker 网络
[root@docker ~]# ip a s #可以看到docker桥接的信息 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default [root@docker ~]# yum -y install bridge-utils [root@docker ~]# brctl show #使用bridge查看桥 bridge name bridge id STP enabled interfaces docker0 8000.02424095a433 no veth7c97f93 [root@docker ~]# docker network ls #使用docker net查看 NETWORK ID NAME DRIVER SCOPE ff11edf26bc7 bridge bridge local 13251fb1e49c host host local 1bc63f3a6d4c none null local
跨主机容器通讯
工具 pipwork flannel
安装所需软件
[root@node1 ~]# yum -y install flannel [root@node1 ~]# yum -y install etcd #用于数据库
编辑配置文件
vim /etc/etcd/etcd.conf ETCD_DATA_DIR="/var/lib/etcd/default.etcd" #ETCD_WAL_DIR="" #ETCD_LISTEN_PEER_URLS="http://localhost:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001" #修改Ip地址为0.0.0.0 #ETCD_MAX_SNAPSHOTS="5" ..... ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.23:2379,http://192.168.1.23:4001" #修改ip为本机地址 [root@node1 ~]# systemctl start etcd [root@node1 ~]# netstat -lnput | grep 2379 查验端口 tcp6 0 0 :::2379 :::* LISTEN 2021/etcd [root@node1 ~]# netstat -lnput | grep 4001 tcp6 0 0 :::4001 :::* LISTEN 2021/etcd [root@node1 ~]# etcdctl set testdir/etstkey0 1000 1000 [root@node1 ~]# etcdctl get testdir/etstkey0 1000 [root@node1 ~]# vim /etc/sysconfig/flanneld # etcd url location. Point this to the server where etcd runs FLANNEL_ETCD_ENDPOINTS="http://192.168.1.23:2379" #修改为本机ip [root@node1 ~]# systemctl start flanneld.service [root@node1 ~]# systemctl enable flanneld.service #启动服务设置开机自启
安装配置docker
修改docker配置文件
[root@node1 ~]# vim /usr/lib/systemd/system/docker.service [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd #将后面多余的删除 ExecReload=/bin/kill -s HUP $MAINPID TimeoutStartSec=0 RestartSec=2
重新加载配置文件,重启docker
[root@node1 ~]# systemctl daemon-reload [root@node1 ~]# systemctl restart docker.service
查看flanner分配的ip
[root@node1 ~]# cat /run/flannel/subnet.env FLANNEL_NETWORK=172.20.0.0/16 FLANNEL_SUBNET=172.20.29.1/24 FLANNEL_MTU=1472 FLANNEL_IPMASQ=false
[root@node1 ~]# vim /etc/docker/daemon.json "bip" : "172.20.29.1/24", "mtu" : "1472" #添加bip和mtu #加载配置文件重启docker [root@node1 ~]# systemctl daemon-reload [root@node1 ~]# systemctl restart docker