docker搭建harbor私有镜像库
Posted zzzynx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker搭建harbor私有镜像库相关的知识,希望对你有一定的参考价值。
创建harbor私有镜像库
在部署节点上:
[[email protected] kubernetes]# cd harbor [[email protected] harbor]# ls common docker-compose.notary.yml ha harbor.v1.4.0.tar.gz LI docker-compose.clair.yml docker-compose.yml harbor.cfg install.sh
[email protected] kubernetes]# mv harbor /opt/
[[email protected] kubernetes]# cd /opt/
[[email protected] opt]# ls
harbor
[[email protected] /]# mkdir data
[[email protected] data]# mkdir harbor
然后cd到kubernetes目录下解压ca.tar.gz,将解压后的ca目录移动到创建的/data/harbor/目录并重命名为cert
[[email protected] harbor]# cd /root/kubernetes [[email protected] kubernetes]# ls bash ca.tar.gz harbor-offline-installer-v1.4.0.tgz image image.tar.gz k8s197.tar.gz [[email protected] kubernetes]# tar zxf ca.tar.gz [[email protected] kubernetes]# ls bash ca ca.tar.gz harbor-offline-installer-v1.4.0.tgz image image.tar.gz k8s197.tar [[email protected] kubernetes]# mv ca /data/harbor/cert [[email protected] kubernetes]# cd /data/harbor/cert/ [[email protected] cert]# ls ca.crt ca.key ca.srl harbor.crt harbor.csr harbor.key
[[email protected] harbor]# cat docker-compose.clair.yml
volumes:
- /data/harbor/clair-db:/var/lib/postgresql/data:z
volumes:
- /data/harbor/notary-db:/var/lib/mysql:z
volumes: - /data/harbor/var/log/harbor/:/var/log/docker/:z - ./common/config/log/:/etc/logrotate.d/:z volumes: - /data/harbor/registry:/storage:z - ./common/config/registry/:/etc/registry/:z volumes: - /data/harbor/database:/var/lib/mysql:z volumes: - /data/harbor/config/:/etc/adminserver/config/:z - /data/harbor/secretkey:/etc/adminserver/key:z - /data/harbor/:/data/:z volumes: - /data/harbor/secretkey:/etc/ui/key:z - /data/harbor/ca_download/:/etc/ui/ca/:z - /data/harbor/psc/:/etc/ui/token/:z volumes: - /data/harbor/job_logs:/var/log/jobs:z - ./common/config/jobservice/app.conf:/etc/jobservice/app.conf:z - /data/secretkey:/etc/jobservice/key:z
4)编辑harbor.cfg文件
三、安装harbor程序:
(1)cd到 /opt/harbor/目录下,执行
? ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at https://reg.yunwei.edu. For more details, please visit https://github.com/vmware/harbor .
(2)验证harbor是否部署成功:
[[email protected] opt]# docker-compose ps ERROR: Can‘t find a suitable configuration file in this directory or any parent. Are you in the right directory? #此报错就是因为没有再/opt/harbor目录下执行 Supported filenames: docker-compose.yml, docker-compose.yaml [[email protected] opt]# cd harbor/ [[email protected] harbor]# docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------------------ harbor-adminserver /harbor/start.sh Up harbor-db /usr/local/bin/docker-entr ... Up 3306/tcp harbor-jobservice /harbor/start.sh Up harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp harbor-ui /harbor/start.sh Up nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp, 0.0.0.0:80->80/tcp registry /entrypoint.sh serve /etc/ ... Up 5000/tcp
可以看到所有容器的状态都为启动,即为成功部署了harbor。
四、各节点设置登陆harbor私有镜像仓库:
/ # ansible all -m shell -a ‘mkdir -p /etc/docker/certs.d/reg.yunwei.edu‘ [WARNING]: Consider using file module with state=directory rather than running mkdir 192.168.253.9 | SUCCESS | rc=0 >> 192.168.253.10 | SUCCESS | rc=0 >> 192.168.253.11 | SUCCESS | rc=0 >> 192.168.253.14 | SUCCESS | rc=0 >>
可以看到四个节点都创建目录成功。注意此操作是在下载了ansible的容器里面。
[[email protected] reg.yunwei.edu]# cp ca.crt /etc/docker/certs.d/reg.yunwei.edu/
192.168.253.9 reg.yunwei.edu
[[email protected] ~]# docker login reg.yunwei.edu Username: admin Password: Login Succeeded
注意需要命令行登陆了镜像库之后,才可以推送或者下载镜像从私有仓库中。
登陆用户名和密码后会有一个默认的library项目,可以选择新建项目。
五、上传镜像到harbor私有镜像仓库:
[[email protected] ~]# docker tag nginx reg.yunwei.edu/test/nginx:latest [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE reg.yunwei.edu/test/nginx latest 719cd2e3ed04 9 days ago 109MB nginx latest 719cd2e3ed04 9 days ago 109MB 。。。
[[email protected] ~]# docker push reg.yunwei.edu/test/nginx The push refers to repository [reg.yunwei.edu/test/nginx] d7acf794921f: Pushed d9569ca04881: Pushed cf5b3c6798f7: Pushed latest: digest: sha256:079aa93463d2566b7a81cbdf856afc6d4d2a6f9100ca3bcbecf24ade92c9a7fe size: 948
私有镜像库的使用
[[email protected] ~]# docker pull reg.yunwei.edu/test/nginx:latest latest: Pulling from test/nginx Digest: sha256:079aa93463d2566b7a81cbdf856afc6d4d2a6f9100ca3bcbecf24ade92c9a7fe Status: Downloaded newer image for reg.yunwei.edu/test/nginx:latest
[[email protected]node1 ~]# docker pull reg.yunwei.edu/test/nginx:latest