要开始使用harbor,得先建项目、添加用户、设置权限等等,我们简单设置下,其余功能可以根据自己的需要进行配置
- Harbor设置
- 点击新建项目,进行项目设置
- 项目名称:起一个有有意义的且不重复的名称
- 访问级别:建议设置为私有,如果是内网也可以设置为公开,这样不需要登录就可以拉取镜像
- 容量限制:根据需要配置,也可以不限制,设置为-1就行
- 代理:会否为中转仓库
- 配置daemon文件
- 把私有镜像仓库设置为信任仓库
- vim /etc/docker/daemon.jso
{
"insecure-registries":
[
"192.168.56.10:8080"
]
}
- 192.168.56.10:8080:为Harbor安装时设置的hostname、http.port
- 准备推入的镜像
- 可以重新打一个镜像,也可以把一个镜像修改下标签,进行镜像仓库的功能测试
- 我们可以先获取一个nginx镜像
[root@common0 harbor]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
- 修改镜像标签
- 通过一下命名修改镜像标签
- docker tag nginx:latest 192.168.56.10:8080/depository/nginx:v1.0
- 推镜像到镜像仓库
- 登录镜像仓库
[root@common0 harbor]# docker login -u admin -p Harbor 192.168.56.10:8080
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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
- 用户名、密码为就是设置的账号,也可以添加新账号及权限
- 验证是否推入成功,登录镜像仓库
- 可以看到刚刚推入的镜像名称、版本信息
- 验证是否功能正常
- 通过执行启动一个Nginx来查看镜像仓库是否能正常提供服务
[root@common0 harbor]# docker run -p 8081:80 --name nginx -td 192.168.56.10:8080/depository/nginx:v1.0
Unable to find image '192.168.56.10:8080/depository/nginx:v1.0' locally
v1.0: Pulling from depository/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3
Status: Downloaded newer image for 192.168.56.10:8080/depository/nginx:v1.0
- 可以看到镜像是从镜像仓库拉取的
- 访问Nginx,地址为192.168.56.10:8081,8081为创建容器时外挂的端口号,如果80端口没有程序使用,也可以用80
- 看到这个提示,说明我们部门的Harbor服务正常提供服务
Harbor是一个专业的镜像服务仓库,功能也是非常的全面,建议可以根据官方的说明文档,把功能熟悉一下,项目上用到的时候,就能及时的想到,官方地址:Harbor docs | Harbor 2.10 Documentation