本文共 7874 字,大约阅读时间需要 26 分钟。
:初步了解仓库是如何管理的。
:可以注册一个官方仓库来上传自己写好的镜像和拉取想要的镜像。 :docker官方文档教你如何Deploy a registry server。 :提供了一个可视化的仓库管理界面。##下载registry镜像[root@server1 ~]# docker search registry[root@server1 ~]# docker pull registry [root@server1 ~]# docker images registry[root@server1 ~]# docker ps -a[root@server1 ~]# docker stop webserverwebserver[root@server1 ~]# docker rm webserver[root@server1 ~]# docker history registry:latest
##运行registry容器[root@server1 ~]# docker run -d --name registry -p 5000:5000 -v /opt/registry:/var/lib/registry registry [root@server1 ~]# docker ps[root@server1 ~]# netstat -antlp[root@server1 ~]# ll -d /opt/registry/
上传镜像到本地仓库,本地镜像在命名时需要加上仓库的ip和端口[root@server1 ~]# docker tag webserver:v4 localhost:5000/webserver:latest[root@server1 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEwebserver v4 047ab2e35274 15 hours ago 31.7MBlocalhost:5000/webserver lastest 047ab2e35274 15 hours ago 31.7MB[root@server1 ~]# docker push localhost:5000/webserver[root@server1 ~]# tree /opt/registry/[root@server1 ~]# curl localhost:5000/v2/_catalog{ "repositories":["webserver"]}
server2上首先安装docker-ce,并且开机自启。[root@server2 yum.repos.d]# cd /etc/docker/[root@server2 docker]# lskey.json[root@server2 docker]# vim daemon.json{ "insecure-registries" : ["192.168.0.1:5000"]}[root@server2 docker]# systemctl reload docker[root@server2 docker]# docker pull 192.168.0.1:5000/webserver[root@server2 docker]# docker images[root@server2 docker]# docker tag 192.168.0.1:5000/webserver webserver[root@server2 docker]# docker run -d webserver
[root@server2 docker]# rm -fr daemon.json[root@server2 docker]# systemctl reload docker生成自己的证书[root@server1 ~]# mkdir -p certs[root@server1 ~]# openssl req \> -newkey rsa:4096 -nodes -sha256 -keyout certs/westos.org.key \> -x509 -days 365 -out certs/westos.org.crt域名westos.org要求在主机上有解析[root@server1 ~]# docker stop registry[root@server1 ~]# docker rm registry
[root@server1 ~]# vim /etc/hosts ##加上reg.westos.org解析,server2相同将westos.org..crt文件复制到 /etc/docker/certs.d/reg.westos.org/ca.crt每个Docker主机上。您无需重启Docker。[root@server1 ~]# mkdir /etc/docker/certs.d/reg.westos.org -p[root@server2 ~]# mkdir /etc/docker/certs.d/reg.westos.org -p[root@server1 ~]# cp certs/westos.org.crt /etc/docker/certs.d/reg.westos.org/ca.crt拷贝证书到其他docker主机[root@server1 ~]# cd /etc/docker/certs.d/reg.westos.org/[root@server1 reg.westos.org]# scp ca.crt server2:/etc/docker/certs.d/reg.westos.org/重新启动注册表,将其定向为使用TLS证书。此命令将certs/目录绑定安装到容器中的/certs/,并设置环境变量,该变量告诉容器在何处找到domain.crt anddomain.key文件。注册表在端口443(默认的HTTPS端口)上运行。[root@server1 ~]# docker run -d --name registry -p 443:443 -v /opt/registry:/var/lib/registry -v "$(pwd)"/certs:/certs -e REGISTRY_HTTP_ADDR=0.0.0.0:443 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/westos.org.crt -e REGISTRY_HTTP_TLS_KEY=/certs/westos.org.key registry
server1上传,server2下载
[root@server1 ~]# docker tag busybox:latest reg.westos.org/busybox:latest[root@server1 ~]# docker push reg.westos.org/busybox:latest[root@server2 ~]# docker pull reg.westos.org/busybox:latest
[root@server1 ~]# mkdir auth[root@server1 ~]# yum provides */htpasswd[root@server1 ~]# yum install -y httpd-tools[root@server1 ~]# htpasswd -c -B auth/htpasswd linux[root@server1 ~]# htpasswd -B auth/htpasswd admin[root@server1 ~]# cat auth/htpasswd [root@server1 ~]# docker run -d --name registry -p 443:443 -v /opt/registry:/var/lib/registry -v "$(pwd)"/certs:/certs -e REGISTRY_HTTP_ADDR=0.0.0.0:443 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/westos.org.crt -e REGISTRY_HTTP_TLS_KEY=/certs/westos.org.key -v "$(pwd)"/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry[root@server1 ~]# ls certs/westos.org.crt westos.org.key[root@server1 ~]# docker ps[root@server1 ~]# docker tag ubuntu:latest reg.westos.org/ubuntu:latest
.
部署:(依赖性 docker 17.06.0-ce+ and docker-compose 1.18.0+)[root@server1 ~]# tar zxf harbor-offline-installer-v1.10.1.tgz [root@server1 ~]# cd harbor/[root@server1 harbor]# mv docker-compose-Linux-x86_64-1.27.0 /usr/local/bin/docker-compose[root@server1 harbor]# chmod +x /usr/local/bin/docker-compose[root@server1 harbor]# docker rm -f registry[root@server1 ~]# cp -r certs/ / ##因为下面配置文件里我选择了放在/下,所以这里将证书复制到根下了。
[root@server1 harbor]# vim harbor.yml ## 修改内容如下hostname: reg.westos.org certificate: /certs/westos.org.crt private_key: /certs/westos.org.keyharbor_admin_password: westos
[root@server1 harbor]# ./install.sh --help[root@server1 harbor]# ./install.sh [root@server1 harbor]# docker ps[root@server1 harbor]# docker-compose ps
[root@server1 harbor]# docker logout reg.westos.orgRemoving login credentials for reg.westos.org[root@server1 harbor]# cat ~/.docker/config.json { "auths": { }[root@server1 harbor]#docker login reg.westos.orgUsername: admin[root@server1 harbor]# docker tag busybox:latest reg.westos.org/library/busybox:latest[root@server1 harbor]# docker push reg.westos.org/library/busybox:latest
[root@server2 ~]# cd /etc/docker/[root@server2 docker]# vim daemon.json{ "registry-mirrors": ["https://reg.westos.org"]}[root@server2 docker]# systemctl reload docker[root@server2 docker]# docker pull busybox
[root@server1 data]# docker logout reg.westos.org[root@server1 data]# docker login reg.westos.orgUsername: linux ##维护人员[root@server1 data]# docker tag ubuntu:latest reg.westos.org/westos/ubuntu:latest[root@server1 data]# docker push reg.westos.org/westos/ubuntu:latest
[root@server2 docker]# docker logout reg.westos.orgRemoving login credentials for reg.westos.org[root@server2 docker]# docker login reg.westos.orgUsern[root@server2 docker]# docker tag webserver:latest reg.westos.org/westos/webserver:latest[root@server2 docker]# docker push reg.westos.org/westos/webserver:latestusername: demo ##访客[root@server2 docker]# docker tag webserver:latest reg.westos.org/westos/webserver:latest[root@server2 docker]# docker push reg.westos.org/westos/webserver:latest
[root@server1 harbor]# docker-compose down [root@server1 harbor]# ./prepare #清理[root@server1 harbor]# ./install.sh --with-notary --with-clair --with-chartmuseum[root@server1 harbor]# docker-compose ps
手动进行扫描,扫描太耗费内存的,所以不建议开启扫描功能。[root@server1 harbor]# docker login reg.westos.orgUsername: admin[root@server1 harbor]# docker push reg.westos.org/library/game2048:latest
部署根证书:[root@server1 ~]# mkdir ~/.docker/tls/reg.westos.org:4443 -p[root@server1 ~]# cd ~/.docker/tls/reg.westos.org:4443[root@server1 reg.westos.org:4443]# cp /etc/docker/certs.d/reg.westos.org/ca.crt .启用docker内容信任:export DOCKER_CONTENT_TRUST=1export DOCKER_CONTENT_TRUST_SERVER=https://reg.westos.org:4443上传镜像:[root@server1 ~]# docker tag yakexi007/game2048:latest reg.westos.org/library/game2048:latest[root@server1 ~]# docker push reg.westos.org/library/game2048:latest当我们修改镜像的名字的时候需要我们输入root key 当我们只修改标签的时候,我们只用输入repository key
为了不让扫描,使得占用的空间越来越大,所以重新修改一下选项[root@server1 ~]# export DOCKER_CONTENT_TRUST=0[root@server1 harbor]# docker-compose down[root@server1 harbor]# ./prepare[root@server1 harbor]# ./install.sh --with-chartmuseum
转载地址:http://enhzi.baihongyu.com/