DevOps 学习笔记(二)| 使用 Harbor

文章介绍了如何将Docker镜像上传到Harbor私有仓库,包括配置Dockerdaemon.json,登录Harbor,打标签并推送镜像。接着,展示了从Harbor拉取镜像到应用服务器的过程。最后,讨论了如何让Jenkins获得使用Docker的权限,以便在CI/CD流程中操作Harbor镜像。
摘要由CSDN通过智能技术生成

1. 上传镜像到 Harbor

首先在CI/CD 服务器中配置 Docker

mkdir -p /etc/docker/
cd /etc/docker/
vim daemon.json

其中的 IP 地址为Harbor 服务器的 IP 地址

{
    "xxx": "xxxx",
    "insecure-registries": ["192.168.80.128:80"]
}

之后重启 Docker 服务,并将 Docker 服务登录 Harbor

systemctl restart docker
docker login -u admin -p Harbor12345 192.168.80.128:80

访问 Harbor 网站,新建项目,项目配置如下
在这里插入图片描述

使用命令将 Docker 镜像追加标识使 Harbor 仓库可以识别,格式为 docker tag 镜像 harbor_ip:port/仓库名/镜像名:版本号

以 Redis 镜像为例,可执行命令

docker tag redis 192.168.80.128:80/repo/my_redis:v1.0.0
docker push 192.168.80.128:80/repo/my_redis:v1.0.0

控制台输出

[root@localhost docker]# docker push 192.168.80.128:80/repo/my_redis:v1.0.0
The push refers to repository [192.168.80.128:80/repo/my_redis]
8e5669d83291: Pushed 
9975392591f2: Pushed 
529cdb636f61: Pushed 
4b8e2801e0f9: Pushed 
9b24afeb7c2f: Pushed 
2edcec3590a4: Pushed 
v1.0.0: digest: sha256:563888f63149e3959860264a1202ef9a644f44ed6c24d5c7392f9e2262bd3553 size: 1573

此时在 Harbor 页面可看到镜像被推送过来

在这里插入图片描述

2. 拉取 Harbor 镜像

应用服务器中配置 Docker,与第一步配置CI/CD 服务器的 Docker 步骤和方法一致,之后需要重启 Docker 服务

如果 Harbor 仓库设置为私有仓库,则还需要登录;否则不需要登录的步骤。因为我们在创建仓库时选择的是公开,因此不需要登录 Harbor 账号

使用命令拉取上传到 Harbor 的镜像,控制台输出如下

root@ubuntu:~# docker pull 192.168.80.128:80/repo/my_redis:v1.0.0
v1.0.0: Pulling from repo/my_redis
a2abf6c4d29d: Pull complete 
c7a4e4382001: Pull complete 
4044b9ba67c9: Pull complete 
c8388a79482f: Pull complete 
413c8bb60be2: Pull complete 
1abfd3011519: Pull complete 
Digest: sha256:563888f63149e3959860264a1202ef9a644f44ed6c24d5c7392f9e2262bd3553
Status: Downloaded newer image for 192.168.80.128:80/repo/my_redis:v1.0.0
192.168.80.128:80/repo/my_redis:v1.0.0

此时使用 docker images 可以看到有 192.168.80.128:80/repo/my_redis 镜像

3. 使用 Jenkins 操作 Harbor

首先我们需要让 Jenkins 拥有使用 Docker 的权限

CI/CD 服务器中进行下面操作

cd /var/run/
ll

其中 docker.sock 文件一项内容如下

srw-rw----.  1 root   docker    0 2月  26 10:42 docker.sock

使用命令对其进行配置

chown root:root docker.sock
chmod o+rw docker.sock

修改后的 docker.sock 属性为

srw-rw-rw-.  1 root   root      0 2月  26 10:42 docker.sock

此时 Jenkins 拥有调用机器中 Docker 的权限

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值