Harbor本地仓库搭建

Harbor本地仓库搭建

1、下载安装docker-compose(需先安装docker)

sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
## 国内镜像
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

更改权限,移动到bin文件夹

[root@localhost opt]# chmod +x docker-compose #添加执行权限
[root@localhost opt]# mv docker-compose /usr/local/bin/
[root@localhost opt]# which docker-compose /usr/local/bin/docker-compose
[root@localhost opt]# docker-compose -v #查看版本
docker-compose version 1.28.5, build c4eb3a1f

2、下载解压habor

[root@localhost opt]# wget https://github.com/goharbor/harbor/releases/download/v2.2.0/harbor-offline-installer-v2.2.0.tgz
[root@localhost opt]# tar -xf harbor-offline-installer-v2.2.0.tgz -C /usr/local/

3、复制yml文件

[root@localhost opt]# cd /usr/local/harbor/
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# vim harbor.yml
hostname: 172.27.160.229 //更改ip
http:
  port: 32090
# https related config //注释https相关配置
# https:
# https port for harbor, default is 443
# port: 443
# The path of cert and key files for nginx
# certificate: /your/certificate/path
# private_key: /your/private/key/path 
...
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: F4m263v6$ //更改默认密码
# Harbor DB configuration
database:
 # The password for the root user of Harbor DB. Change this before any production use.
password: N1r571x6#
/data/harbor

4、安装

[root@localhost harbor]# ./install.sh 
    Creating harbor-log ... done
    Creating harbor-portal ... done
    Creating harbor-db     ... done
    Creating registry      ... done
    Creating registryctl   ... done
    Creating redis         ... done
    Creating harbor-core   ... done
    Creating harbor-jobservice ... done
    Creating nginx             ... done
    ✔ ----Harbor has been installed and started successfully.----
//查看镜像启动
[root@localhost harbor]# ss -antl
State       Recv-Q Send-Q                  Local Address:Port                                 Peer Address:Port              
LISTEN      0      128                         127.0.0.1:1514                                            *:*                  
LISTEN      0      128                                 *:80                                              *:*                  
LISTEN      0      128                                 *:22                                              *:*                  
LISTEN      0      100                         127.0.0.1:25                                              *:*                  
LISTEN      0      128                                :::80                                             :::*                  
LISTEN      0      128                                :::22                                             :::*                  
LISTEN      0      100                               ::1:25 
[root@localhost harbor]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED          STATUS                    PORTS                                   NAMES
be60c8592b69   goharbor/nginx-photon:v2.2.0         "nginx -g 'daemon of…"   49 seconds ago   Up 47 seconds (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp   nginx
6225e71bed72   goharbor/harbor-jobservice:v2.2.0    "/harbor/entrypoint.…"   49 seconds ago   Up 47 seconds (healthy)                                           harbor-jobservice
2dffb4f31b7e   goharbor/harbor-core:v2.2.0          "/harbor/entrypoint.…"   49 seconds ago   Up 48 seconds (healthy)                                           harbor-core
9660564de6fa   goharbor/harbor-registryctl:v2.2.0   "/home/harbor/start.…"   51 seconds ago   Up 49 seconds (healthy)                                           registryctl
de76e9cb68db   goharbor/redis-photon:v2.2.0         "redis-server /etc/r…"   51 seconds ago   Up 49 seconds (healthy)                                           redis
0bf4e57f20e7   goharbor/registry-photon:v2.2.0      "/home/harbor/entryp…"   51 seconds ago   Up 49 seconds (healthy)                                           registry
1e326ff98168   goharbor/harbor-db:v2.2.0            "/docker-entrypoint.…"   51 seconds ago   Up 49 seconds (healthy)                                           harbor-db
95f8aece51a8   goharbor/harbor-portal:v2.2.0        "nginx -g 'daemon of…"   51 seconds ago   Up 49 seconds (healthy)                                           harbor-portal
51ce24305539   goharbor/harbor-log:v2.2.0           "/bin/sh -c /usr/loc…"   52 seconds ago   Up 50 seconds (healthy)   127.0.0.1:1514->10514/tcp               harbor-log

5、设置开机启动脚本

[root@localhost harbor]# vim startall.sh

#! /bin/bash
cd /usr/local/harbor
docker-compose stop && docker-compose start

// 为rc.loacl和脚本增加执行权限
[root@localhost harbor]# chmod  +x startall.sh 
[root@localhost harbor]# chmod +x /etc/rc.d/rc.local 
[root@localhost harbor]# chmod +x /etc/rc.local 
[root@localhost opt]# vim /etc/rc.local

#!/bin/bash
/bin/bash /usr/local/harbor/startall.sh

将harbor仓库的地址写进docker中,让docker可以连接到harbor仓库【这里是客户端】

#添加insecure-registries本机ip,重启守护进程
[root@localhost harbor]# vim /etc/docker/daemon.json 
{
  "insecure-registries": ["172.27.160.229:32090"]
}
//配置守护进程会冲突问题
vim /usr/lib/systemd/system/docker.service
//查看是否有registriy的选项,如果有记得删除
//重启守护进程和compose
[root@localhost harbor]# systemctl daemon-reload 
[root@localhost harbor]# systemctl restart docker.service

6、输入IP访问,创建用户

img
创建项目
为项目添加用户
查看推送命令
推送镜像

#登入本地仓库(需在harbor界面创建用户)
[root@localhost ~]# docker login 192.168.163.180 -u admin -p admin123
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
# 镜像制作
# 示例 以redis为例
//拉取redis镜像
[root@localhost ~]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
7d63c13d9b9b: Pull complete 
a2c3b174c5ad: Pull complete 
283a10257b0f: Pull complete 
7a08c63a873a: Pull complete 
0531663a7f55: Pull complete 
9bf50efb265c: Pull complete 
Digest: sha256:a89cb097693dd354de598d279c304a1c73ee550fbfff6d9ee515568e0c749cfe
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
# 更改镜像,命令格式: tag docker tag SOURCE_IMAGE[:TAG] 192.168.163.180/csdn/REPOSITORY[:TAG]
[root@localhost ~]# docker tag redis 192.168.163.180/csdn/redis:latest
# 查看一下镜像
[root@localhost ~]# docker images
REPOSITORY                   TAG       IMAGE ID       CREATED       SIZE
192.168.163.180/csdn/redis   latest    7faaec683238   2 weeks ago   113MB
redis                        latest    7faaec683238   2 weeks ago   113MB

#推送镜像,命令格式:docker push 192.168.163.180/csdn/REPOSITORY[:TAG]
[root@localhost ~]# docker push 192.168.163.180/csdn/redis:latest
The push refers to repository [192.168.163.180/csdn/redis]
146262eb3841: Pushed 
0bd13b42de4d: Pushed 
6b01cc47a390: Pushed 
8b9770153666: Pushed 
b43651130521: Pushed 
e8b689711f21: Pushed 
latest: digest: sha256:5d30f5c16e473549ad7c950b0ac3083039719b1c9749519c50e18017dd4bfc54 size: 1573
jy	CSDNjy@123

查看镜像
拉取命令查看

docker pull 192.168.163.180/csdn/redis:latest

删除原有镜像并拉取

[root@localhost ~]# docker images
REPOSITORY                   TAG       IMAGE ID       CREATED       SIZE
192.168.163.180/csdn/redis   latest    7faaec683238   2 weeks ago   113MB
redis                        latest    7faaec683238   2 weeks ago   113MB
[root@localhost ~]# docker rmi -f 7faaec683238
Untagged: 192.168.163.180/csdn/redis:latest
Untagged: 192.168.163.180/csdn/redis@sha256:5d30f5c16e473549ad7c950b0ac3083039719b1c9749519c50e18017dd4bfc54
Untagged: redis:latest
Untagged: redis@sha256:a89cb097693dd354de598d279c304a1c73ee550fbfff6d9ee515568e0c749cfe
Deleted: sha256:7faaec68323851b2265bddb239bd9476c7d4e4335e9fd88cbfcc1df374dded2f
Deleted: sha256:e6deb90762475cda72e21895911f830ed99fd1cc6d920d92873270be91235274
Deleted: sha256:2649acad13241d9c8d81e49357bc66cce459b352ded7f423d70ede7bd3bb7b89
Deleted: sha256:64007bba5fc220df4d3da33cecdc2d55dd6a73528c138b0fa1acd79fd6a9c217
Deleted: sha256:b2cc2f1bf8b1cca8ba7c19e1697f7b73755903ad8f880b83673fd6a697aca935
Deleted: sha256:fbd1283ab782925be4d990bd4bebe9ad5e5cf9a525abfb6fa87465e072da9d31
Deleted: sha256:e8b689711f21f9301c40bf2131ce1a1905c3aa09def1de5ec43cf0adf652576e
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@localhost ~]# docker pull 192.168.163.180/csdn/redis:latest
latest: Pulling from csdn/redis
7d63c13d9b9b: Pull complete 
a2c3b174c5ad: Pull complete 
283a10257b0f: Pull complete 
7a08c63a873a: Pull complete 
0531663a7f55: Pull complete 
9bf50efb265c: Pull complete 
Digest: sha256:5d30f5c16e473549ad7c950b0ac3083039719b1c9749519c50e18017dd4bfc54
Status: Downloaded newer image for 192.168.163.180/csdn/redis:latest
192.168.163.180/csdn/redis:latest
[root@localhost ~]# docker images
REPOSITORY                   TAG       IMAGE ID       CREATED       SIZE
192.168.163.180/csdn/redis   latest    7faaec683238   2 weeks ago   113MB
  • 9
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值