私有镜像仓库harbor搭建

一、安装docker

https://blog.csdn.net/weixin_63634809/article/details/124560933

#目前 Docker 只能支持 64 位系统。
#!/bin/bash
#1.#关闭防火墙 
systemctl stop firewalld.service
setenforce 0
#2.#安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2 
--------------------------------------------------------------------------------
#yum-utils:提供了 yum-config-manager 工具。
#device mapper: 是Linux内核中支持逻辑卷管理的通用设备映射机制,它为实现用于存储资源管理的块设备驱动提供了一个高度模块化的内核架构。
#device mapper存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
--------------------------------------------------------------------------------
#3.#设置阿里云镜像源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

#4.#安装 Docker-CE 社区版并设置为开机自动启动
yum install -y docker-ce
#5.配置镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://olut9u2k.mirror.aliyuncs.com"],
   "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

#6.#查看 docker 版本信息
docker version

二、安装docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

三、下载harbor

官网:https://github.com/goharbor/harbor/releases
在这里插入图片描述

#上传并解压:(我下载的是v2.3.0版本)
tar -zxvf harbor-offline-installer-v2.3.0.tgz
cd harbor
cp harbor.yml.tmpl  harbor.yml
#更改配置文件
vim harbor.yml
(私网内不需要https,把https注释掉配置下hostname,其他地方可以不用动)

在这里插入图片描述

四、修改配置文件

#配置daemon.json文件(配置harbor的地址与harbor.yaml里的hostname一致)
[root@harbor harbor]# cat /etc/docker/daemon.json
{
    
    
  "registry-mirrors": ["https://olut9u2k.mirror.aliyuncs.com"],
  "insecure-registries":["www.harbor.com"]
}
#重启docker
[root@harbor harbor]#systemctl  daemon-reload
[root@harbor harbor]#systemctl  restart docker

#配置本地hosts文件
[root@harbor harbor]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.192.177 www.harbor.com

五、启动harbor并验证

[root@harbor ~]# cd harbor
[root@harbor harbor]# ./prepare

[root@harbor harbor]# ./install.sh
.......
.......
.......
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating harbor-db     ... done
Creating registryctl   ... done
Creating redis         ... done
Creating registry      ... done
Creating harbor-core   ... done
Creating nginx             ... done
Creating harbor-jobservice ... done
✔ ----Harbor has been installed and started successfully.----
[root@harbor harbor]#
[root@harbor harbor]# docker-compose ps
      Name                     Command                  State                      Ports
--------------------------------------------------------------------------------------------------------
harbor-core         /harbor/entrypoint.sh            Up (healthy)
harbor-db           /docker-entrypoint.sh 96 13      Up (healthy)
harbor-jobservice   /harbor/entrypoint.sh            Up (healthy)
harbor-log          /bin/sh -c /usr/local/bin/ ...   Up (healthy)   127.0.0.1:1514->10514/tcp
harbor-portal       nginx -g daemon off;             Up (healthy)
nginx               nginx -g daemon off;             Up (healthy)   0.0.0.0:80->8080/tcp,:::80->8080/tcp
redis               redis-server /etc/redis.conf     Up (healthy)
registry            /home/harbor/entrypoint.sh       Up (healthy)
registryctl         /home/harbor/start.sh            Up (healthy)
[root@harbor harbor]#
这表示harbor已经正常启动正常访问

登录验证

[root@harbor harbor]# docker login www.harbor.com
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

web页面输入ip可以正常访问
输入用户名admin 密码Harbor12345
项目》》新建项目》》test》》给镜像打标签并上传到仓库

[root@harbor harbor]# docker tag nginx:latest www.harbor.com/test/nginx:latest
[root@harbor harbor]# docker push www.harbor.com/test/nginx:latest
The push refers to repository [www.harbor.com/test/nginx]
d874fd2bc83b: Pushed
32ce5f6a5106: Pushed
f1db227348d0: Pushed
b8d6e692a25e: Pushed
e379e8aedd4d: Pushed
2edcec3590a4: Pushed
latest: digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3 size: 1570
[root@harbor harbor]#

在这里插入图片描述

六、其他机器登录harbor仓库

#配置hosts
[root@master ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.192.177 www.harbor.com
#配置私有镜像仓库地址
[root@master ~]# cat /etc/docker/daemon.json
{
    
    
  "registry-mirrors": ["https://olut9u2k.mirror.aliyuncs.com"],
  "insecure-registries": ["www.harbor.com"]
}

#登录测试
[root@master ~]# docker login www.harbor.com
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@master ~]# docker pull www.harbor.com/test/harbor-exporter@sha256:398f5a2058d77b5c66942f78ab871ce69990d75121b5b7ef3af7283cc73bc7a4
www.harbor.com/test/harbor-exporter@sha256:398f5a2058d77b5c66942f78ab871ce69990d75121b5b7ef3af7283cc73bc7a4: Pulling from test/harbor-exporter
7ec05e6a2d8c: Pull complete
1ae7147f967e: Pull complete
4e0937eaf2ed: Pull complete
f629f47a74f3: Pull complete
e6f36d77f27d: Pull complete
Digest: sha256:398f5a2058d77b5c66942f78ab871ce69990d75121b5b7ef3af7283cc73bc7a4
Status: Downloaded newer image for www.harbor.com/test/harbor-exporter@sha256:398f5a2058d77b5c66942f78ab871ce69990d75121b5b7ef3af7283cc73bc7a4
www.harbor.com/test/harbor-exporter@sha256:398f5a2058d77b5c66942f78ab871ce69990d75121b5b7ef3af7283cc73bc7a4

#上传镜像测试
[root@master ~]# docker tag centos:latest www.harbor.com/test/centos:latest
[root@master ~]# docker push   www.harbor.com/test/centos:latest
The push refers to repository [www.harbor.com/test/centos]
74ddd0ec08fa: Pushed
latest: digest: sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc size: 529

在这里插入图片描述

[root@master ~]# docker pull www.harbor.com/test/centos:latest
latest: Pulling from test/centos
a1d0c7532777: Already exists
Digest: sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc
Status: Downloaded newer image for www.harbor.com/test/centos:latest
www.harbor.com/test/centos:latest
[root@master ~]# docker images
REPOSITORY                                                     TAG              IMAGE ID       CREATED         SIZE
www.harbor.com/test/centos                                     latest           5d0da3dc9764   10 months ago   231MB
[root@master ~]#

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45720992/article/details/131051354