部署 harbor 私有仓库
环境、软件准备
本次演示环境,我是在虚拟机Linux RedHat7上操作,以下是安装的软件及版本:
Docker:version 18.06.1 Docker-compose: version 1.12.0 Harbor: version 1.1.2
1.Docker-compose 安装
[root@foundation81 ~]# wget https://github.com/docker/compose/releases/download/1.12.0/docker-compose-Linux-x86_64
[root@foundation81 ~]# mv docker-compose-Linux-x86_64 /usr/bin/docker-compose
[root@foundation81 ~]# chmod +x /usr/bin/docker-compose
[root@foundation81 ~]# docker-compose --version ##测试下docker-compose是否安装成功
docker-compose version 1.12.0, build b31ff33

2.Harbor 服务搭建
1)下载Harbor安装文件 从 github harbor 官网 release 页面下载指定版本的安装包。
[root@foundation81 Desktop]wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-offline-installer-v1.1.2.tgz
[root@foundation81 Desktop]# tar -xvf harbor-offline-installer-0.5.0.tgz
2)配置Harbor
解压缩之后,harbor目录下会生成harbor.cfg文件,该文件就是Harbor的配置文件。
[root@foundation81 Desktop]# cd harbor/
[root@foundation81 harbor]# vim harbor.cfg
hostname = 172.25.254.81

3)启动 Harbor
[root@foundation81 harbor]# ./install.sh



启动完成后,我们访问刚设置的hostname即可 http://172.25.254.81,默认是80端口,

<1>新建项目
我们新建一个名称为test的项目,设置不公开。
注意:当项目设为公开后,任何人都有此项目下镜像的读权限。命令行用户不需要“docker login”就可以拉取此项目下的镜像。

<2>push本地镜像
新建项目完毕后,我们就可以用admin账户提交本地镜像到Harbor仓库了。例如我们提交本地nginx镜像:
1.admin登录

登录报错:
Error response from daemon: Get http://172.25.254.81/v2/: dial tcp 172.25.254.81: connect: connection refused
最终解决方案如下:
在需要登陆的docker client端修改/usr/lib/systemd/system/docker.service文件,在里面修改ExecStart那一行,增加--insecure-registry=172.25.254.81,然后重启docker (systemctl daemon-reload systemctl restart docker)
[root@foundation81 ~]# 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 --insecure-registry=172.25.254.81 ExecReload=/bin/kill -s HUP $MAINPID

2.给镜像打tag
[root@foundation81 harbor]# docker tag nginx 172.25.254.81/test/nginx:latest

3.push到仓库
[root@foundation81 harbor]# docker push 172.25.254.81/test/nginx

上传完毕后,登录Web Harbor,选择项目,项目名称test,就可以查看刚才上传的nginx image了。

3.创建用户并分配权限
我们刚一直是用admin操作,实际应用中我们使用每个人自己的账户登录。所以就需要新建用户,同时为了让用户有权限操作已经创建的项目,还必须将该用户添加到该项目成员中。
点击admin-->Add User,输入用户名、邮箱、密码等信息。

将zzz用户添加到test项目成员中,填写姓名,选择角色。
test --> Add Member -->Developer

使用zzz用户本地模拟操作pull刚上传的nginx镜像。
1.先移除tag
[root@foundation81 ~]# docker rmi 172.25.254.81/test/nginx:latest

2.退出admin用户,登录wanyang用户
[root@foundation81 ~]# docker logout 172.25.254.81
Removing login credentials for 172.25.254.81
[root@foundation81 ~]# docker login 172.25.254.81
Username: zzz 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

3.pull harbor镜像到本地
[root@foundation81 ~]# docker pull 172.25.254.81/test/nginx:latest

|