Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署私有环境内的Registry也是非常必要的。Harbor是由VMware公司开源的企业级的Docker Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能
搭建私有仓库的软件
下面我将介绍搭建harbor私有仓库以及进行简单的应用
软件环境
软件 | 版本 |
---|---|
Docker engine | 版本 17.06.0-ce+ 或更高版本 |
Docker Compose | 版本 1.18.0 或更高版本 |
harbor | 版本2.5.3或更高版本 |
Releases · goharbor/harbor (github.com)
[root@docker ~]# mkdir /myharbor
[root@docker ~]# cd /myharbor/
[root@docker myharbor]# ls
[root@docker myharbor]# ls
docker-compose harbor-offline-installer-v2.5.3.tgz
[root@docker myharbor]# chmod +x docker-compose
[root@docker myharbor]# ls
docker-compose harbor-offline-installer-v2.5.3.tgz
[root@docker myharbor]# mv docker-compose /usr/bin/
[root@docker myharbor]# tar xf harbor-offline-installer-v2.5.3.tgz
[root@docker myharbor]# cd harbor
[root@docker harbor]# ls
common.sh harbor.v2.5.3.tar.gz harbor.yml.tmpl install.sh LICENSE prepare
[root@docker harbor]# mv harbor.yml.tmpl harbor.yml
[root@docker harbor]# vim harbor.yml
hostname: 192.168.31.129
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 8089
[root@docker harbor]# ./install.sh
默认账号admin
密码Harbor12345
准备上传本机的nginx:latest这个镜像
[root@docker harbor]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://52152375.mirror.aliyuncs.com"],
"insecure-registries":["192.168.31.129:8089"]
}
[root@docker harbor]# systemctl daemon-reload
[root@docker harbor]# systemctl restart docker
[root@docker harbor]# docker login 192.168.31.129:8089
Username: felix
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
用户和密码是当时在harbor网页上新建的用户和密码
[root@docker harbor]# docker tag nginx:latest 192.168.31.129:8089/myrepo/nginx:latest
[root@docker harbor]# docker push 192.168.31.129:8089/myrepo/nginx
发现了上传的镜像!
[root@docker harbor]# docker rmi nginx:latest
[root@docker harbor]# docker pull 192.168.31.129:8089/myrepo/nginx
[root@docker harbor]# docker images
测试成功!
docker login登陆不上harbor
harbor通过./install安装失败