14-docker系列-docker之harbor仓库的使用

声明:本文乃“运维家”原创,转载请注明出处,更多内容请关注公众号“运维家”。

图片

主旨

上一章我们介绍了如何搭建harbor仓库,我们现在看看应该如何进行注册,使用,配置等。

环境

linux环境
docker环境
harbor仓库

新建用户

点击 “用户管理” -- “创建用户”

图片

图片

新建项目并添加成员

点击 “项目” -- “新建项目”,相关信息配置好之后,点击“确定”按钮

图片

图片

点击刚才创建的项目

图片

点击“成员” -- “添加成员”,在这里添加上我们刚新建的用户“yunweijia”,并选择相关角色,不同成员的权限不一致,我这里就配置成“项目管理员”了。

图片

图片

图片

配置http

docker登录仓库默认的方式是https,但是我们一章中创建的是http的,那么我们是不是就无法登录了呢?我们这里来介绍下如何让docker使用http的方式登录仓库。

[yunweijia@localhost harbor]$ sudo vim /etc/docker/daemon.json 
# 第二行是新增的,IP为harbor仓库的访问地址
{
  "registry-mirrors": ["http://hub-mirror.c.163.com/"],
  "insecure-registries": ["192.168.112.130"]
}
[yunweijia@localhost harbor]$ sudo systemctl restart docker
[yunweijia@localhost harbor]$ 

登录仓库

我们创建完用户之后,需要在linux服务器上进行登录,之后才可以进行上传下载镜像。

[yunweijia@localhost harbor]$ sudo docker login 192.168.112.130
Username: yunweijia
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
[yunweijia@localhost harbor]$

上传镜像

先查看下系统有多少个镜像

[yunweijia@localhost harbor]$ sudo docker images
REPOSITORY                      TAG        IMAGE ID       CREATED        SIZE
yunweijia                       jenkins    976d65da21b9   7 days ago     874MB
yunweijia                       python3    31255eafafc3   7 days ago     662MB
redis                           latest     f1b6973564e9   3 weeks ago    113MB
nginx                           latest     c316d5a335a5   3 weeks ago    142MB
[yunweijia@localhost harbor]$

我们选择一个上传,可以先打个tag,这样子他会自行寻找目录,否则你上传的镜像,他都不知道放到哪里,比如下面可以这样子操作;

[yunweijia@localhost harbor]$ sudo docker tag yunweijia:python3 192.168.112.130/yunwei/yunweijia:python3

然后使用push命令进行上传;

[yunweijia@localhost harbor]$ sudo docker push 192.168.112.130/yunwei/yunweijia:python3
The push refers to repository [192.168.112.130/yunwei/yunweijia]
d05eb0188b0e: Pushed 
2ae72c1b8b42: Pushed 
661441a515a6: Pushed 
174f56854903: Pushed 
python3: digest: sha256:db23cd3c6e53cac4f76d427b0640ba5e63165c4fde3f73aaeaf36b1a366f2f84 size: 1161
[yunweijia@localhost harbor]$

登录harbor仓库里面看看;

图片

图片

下载镜像

查看镜像,看下我们现有多少镜像;

[yunweijia@localhost harbor]$ sudo docker images
REPOSITORY                      TAG        IMAGE ID       CREATED        SIZE
yunweijia                       jenkins    976d65da21b9   7 days ago     874MB
yunweijia                       python3    31255eafafc3   7 days ago     662MB
redis                           latest     f1b6973564e9   3 weeks ago    113MB
nginx                           latest     c316d5a335a5   3 weeks ago    142MB
[yunweijia@localhost harbor]$

使用pull命令进行下载;

[yunweijia@localhost harbor]$ sudo docker pull 192.168.112.130/yunwei/yunweijia:python3
python3: Pulling from yunwei/yunweijia
Digest: sha256:db23cd3c6e53cac4f76d427b0640ba5e63165c4fde3f73aaeaf36b1a366f2f84
Status: Downloaded newer image for 192.168.112.130/yunwei/yunweijia:python3
192.168.112.130/yunwei/yunweijia:python3
[yunweijia@localhost harbor]$

再次查看下镜像,发现已经多了一个下载的镜像;

[yunweijia@localhost harbor]$ sudo docker images
REPOSITORY                         TAG        IMAGE ID       CREATED        SIZE
yunweijia                          jenkins    976d65da21b9   7 days ago     874MB
192.168.112.130/yunwei/yunweijia   python3    31255eafafc3   7 days ago     662MB
yunweijia                          python3    31255eafafc3   7 days ago     662MB
redis                              latest     f1b6973564e9   3 weeks ago    113MB
nginx                              latest     c316d5a335a5   3 weeks ago    142MB
[yunweijia@localhost harbor]$ 

至此,docker系列就更新完毕了。各位老板欢迎后台留言想看的内容。

posted @ 2022-02-21 12:41  郭-吉尔伽美什  阅读(25)  评论(0)    收藏  举报