harbor部署安装及docker push镜像

harbor部署安装及docker push镜像

  • 背景介绍
    • 环境介绍
    • 安装版本
  • habor安装
    • 基础安装
    • 配置docker登录
    • harbor启动
    • harbor界面查看
  • push镜像
    • 相关语法简介
    • harbor页面创建项目
    • push实战
      • 操作命令
      • harbor界面验证

背景介绍

因项目需要,需搭建私有化仓库,特在本地搭建进行验证。

环境介绍

linux的版本 :

$cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

docker的版本:

$docker version
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:49:57 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:48:24 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

安装版本

harbor.v2.1.0

habor安装

基础安装

#下载安装包
[root@localhost src] wget -c https://storage.googleapis.com/harbor-releases/release-2.1.0/harbor-offline-installer-v2.1.0.tgz

#解压缩及创建对应的文件夹
[root@cydocker][~/package]
$ll
total 543096
-rw-r--r-- 1 root root 556130191 Feb 28 10:36 harbor-offline-installer-v2.1.0.tgz

[root@cydocker][~/package]
$tar -zxvf harbor-offline-installer-v2.1.0.tgz

[root@cydocker][~/package]
$mv harbor /usr/local/

[root@cydocker][~/package]
$cd /usr/local/harbor

[root@cydocker][~/package/harbor]
$cp harbor.yml.tmpl harbor.yml

[root@cydocker][/usr/local/harbor]
$mkdir data

[root@cydocker][/usr/local/harbor]
$mkdir log 

# 修改配置文件(我只修改了下面粘贴的地方,其余的就是原始文件带的)
[root@cydocker][/usr/local/harbor]
$vim harbor.yml

hostname: 192.168.56.116 #修改为自己的ip地址
http:
  port: 8081 #我自己修改了端口
  
harbor_admin_password: habor123456 # 自己修改了密码

data_volume: /usr/local/harbor/data #自己修改了数据存储路径

log:
  level: info
  local:
    rotate_count: 50
    rotate_size: 200M
    location: /usr/local/harbor/log #自己修改了日志路径

[root@cydocker][~/package/harbor]
$ bash prepare

[root@cydocker][~/package/harbor]
$ bash install.sh

配置docker登录

[root@cydocker][~/package]
$cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://cd5mi9sb.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.56.116:8081"] #主要添加这一行,要不docker push会报错
}

[root@cydocker][~/package]
$systemctl daemon-reload && systemctl restart docker

[root@cydocker][~/package/harbor]
$docker login 192.168.56.116:8081
Username: admin
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@cydocker][~/package/harbor]
$docker-compose up -d
harbor-log is up-to-date
registryctl is up-to-date
registry is up-to-date
redis is up-to-date
harbor-db is up-to-date
harbor-portal is up-to-date
harbor-core is up-to-date
harbor-jobservice is up-to-date
nginx is up-to-date

harbor界面查看

默认用户:admin
密码:默认为 Harbor12345,因为我的已经在habor.ym文件中改成了habor123456

harbor部署安装及docker push镜像_第1张图片
登录成功页面如下:
harbor部署安装及docker push镜像_第2张图片

push镜像

相关语法简介

#1 在本地登录到远程仓库
docker login --username=[用户名] -p=[密码]  远程ip:端口

#2 拉取镜像
docker pull 镜像名称/镜像ID

#3 给镜像打标签
docker tag [待打标签的镜像id] [远程ip:端口/harbor项目名称/镜像名称]:[版本号]

#4 push镜像
docker push [远程ip:端口/harbor项目名称/镜像名称]:[版本号]

harbor页面创建项目

harbor部署安装及docker push镜像_第3张图片
我自己创建的如下:
harbor部署安装及docker push镜像_第4张图片

push实战

操作命令

[root@cydocker][~/package]
$ docker pull nginx

[root@cydocker][/usr/local/harbor]
$docker images
REPOSITORY                                  TAG          IMAGE ID       CREATED         SIZE
nginx                                       latest       605c77e624dd   14 months ago   141MB

[root@cydocker][/usr/local/harbor]
$docker tag 605c77e624dd  192.168.56.116:8081/test_project/nginx-01:v1

[root@cydocker][/usr/local/harbor]
$docker images
REPOSITORY                                  TAG          IMAGE ID       CREATED         SIZE
192.168.56.116:8081/test_project/nginx-01   v1           605c77e624dd   14 months ago   141MB
nginx                                       latest       605c77e624dd   14 months ago   141MB

[root@cydocker][~/package/harbor]
$docker login 192.168.56.116:8081
Username: admin
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

[root@cydocker][/usr/local/harbor]
$docker push 192.168.56.116:8081/test_project/nginx-01:v1
The push refers to repository [192.168.56.116:8081/test_project/nginx-01]
d874fd2bc83b: Pushed 
32ce5f6a5106: Pushed 
f1db227348d0: Pushed 
b8d6e692a25e: Pushed 
e379e8aedd4d: Pushed 
2edcec3590a4: Pushed 
v1: digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3 size: 1570

harbor界面验证

已经看到页面中有刚才push的镜像了
harbor部署安装及docker push镜像_第5张图片
至此,已经实现了自己的需求,大家如果有啥需要了解的,请及时和我留言沟通。

你可能感兴趣的:(linux,docker,运维)