CentOS安装部署Harbor——搭建Docker私有仓库

harbor——搭建Docker私有仓库

harbor介绍

Harbor 是一个开源的可信云原生注册表项目,用于存储、签名和扫描内容。Harbor 通过添加用户通常需要的功能(例如安全性、身份和管理)来扩展开源 Docker Distribution。让注册表更接近构建和运行环境可以提高图像传输效率。Harbor 支持在注册中心之间复制镜像,还提供高级安全功能,例如用户管理、访问控制和活动审计。

harbor安装

环境:harbor-v2.1.0、CentOS7.9(192.168.152.139)、docker、docker-compose
v2.7.1的安装步骤相同

1、前提条件是安装好docker和docker-compose
2、下载harbor的源码

​ 官方下载地址https://github.com/goharbor/harbor/releases

3、上传到Linux服务器并解压
[root@docker harbor]# ls
harbor-offline-installer-v2.1.0.tgz
[root@docker harbor]# tar xf harbor-offline-installer-v2.1.0.tgz 
[root@docker harbor]# ls
harbor  harbor-offline-installer-v2.1.0.tgz

4、复制harbor.yml.tmpl文件命名为harbor.yml
[root@docker harbor]# cd harbor/
[root@docker harbor]# ls
common.sh  harbor.v2.1.0.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@docker harbor]# cp harbor.yml.tmpl harbor.yml
[root@docker harbor]# ls
common.sh  harbor.v2.1.0.tar.gz  harbor.yml  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@docker harbor]# vim harbor.yml

5、修改harbor.yml配置文件
[root@harbor harbor]# vim harbor.yml
hostname: 192.168.1.131  #修改
  port: 8089  #修改

#注释掉了https的配置
#其他的配置没有修改
6、下载并安装docker官方的容器编排工具docker-compose
[root@harbor harbor]# curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o docker-compose		#下载
[root@harbor harbor]# chmod +x docker-compose	# 授予可执行权限
[root@docker harbor]# cp docker-compose /usr/bin/

7、运行install.sh
[root@docker harbor]# ./install.sh		
[root@docker harbor]# 
[root@docker harbor]# docker ps
CONTAINER ID   IMAGE                                COMMAND                   CREATED              STATUS                        PORTS                                       NAMES
5ace6026acb8   goharbor/nginx-photon:v2.1.0         "nginx -g 'daemon of…"   About a minute ago   Up About a minute (healthy)   0.0.0.0:8089->8080/tcp, :::8089->8080/tcp   nginx
39d1bacc785a   goharbor/harbor-jobservice:v2.1.0    "/harbor/entrypoint.…"   About a minute ago   Up About a minute (healthy)                                               harbor-jobservice
be367859f57e   goharbor/harbor-core:v2.1.0          "/harbor/entrypoint.…"   About a minute ago   Up About a minute (healthy)                                               harbor-core
9a89005d4766   goharbor/registry-photon:v2.1.0      "/home/harbor/entryp…"   About a minute ago   Up About a minute (healthy)                                               registry
e4bb9a2c8bbb   goharbor/harbor-db:v2.1.0            "/docker-entrypoint.…"   About a minute ago   Up About a minute (healthy)                                               harbor-db
788fd220f89b   goharbor/harbor-registryctl:v2.1.0   "/home/harbor/start.…"   About a minute ago   Up About a minute (healthy)                                               registryctl
b8effefc56bf   goharbor/redis-photon:v2.1.0         "redis-server /etc/r…"   About a minute ago   Up About a minute (healthy)                                               redis
13dac698bf9c   goharbor/harbor-portal:v2.1.0        "nginx -g 'daemon of…"   About a minute ago   Up About a minute (healthy)                                               harbor-portal
17bd3027bc72   goharbor/harbor-log:v2.1.0           "/bin/sh -c /usr/loc…"   About a minute ago   Up About a minute (healthy)   127.0.0.1:1514->10514/tcp                   harbor-log
[root@docker harbor]# 
8、浏览器访问192.168.152.139:8089

默认用户名:admin
默认密码:Harbor12345

CentOS安装部署Harbor——搭建Docker私有仓库_第1张图片

9、创建用户

CentOS安装部署Harbor——搭建Docker私有仓库_第2张图片

10、新建项目

CentOS安装部署Harbor——搭建Docker私有仓库_第3张图片

11、在项目中标记镜像

​ 此处以nginx:latest为例

[root@docker ~]# docker tag nginx:latest 192.168.152.139:8089/sanchuang/nginx:latest
[root@docker ~]# docker images
REPOSITORY                             TAG            IMAGE ID       CREATED         SIZE
192.168.152.139:8089/sanchuang/nginx   latest         3f8a00f137a0   5 weeks ago     142MB
nginx                                  latest         3f8a00f137a0   5 weeks ago     142MB

12、使用创建的用户登录私有库
[root@docker ~]# docker login 192.168.152.139:8089
Username: zhang          
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@docker ~]#
13、推送镜像到sanchuang项目
[root@docker ~]# docker push 192.168.152.139:8089/sanchuang/nginx:latest
The push refers to repository [192.168.152.139:8089/sanchuang/nginx]
3ea1bc01cbfe: Pushed 
a76121a5b9fd: Pushed 
2df186f5be5c: Pushed 
21a95e83c568: Pushed 
81e05d8cedf6: Pushed 
4695cdfb426a: Pushed 
latest: digest: sha256:7f797701ded5055676d656f11071f84e2888548a2e7ed12a4977c28ef6114b17 size: 1570
[root@docker ~]# 

14、测试:使用另一台机器的docker拉取harbor库中的镜像
[root@docker ~]# vim /etc/docker/daemon.json	# 修改配置文件(如果不存在就新建)
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries" : ["192.168.1152.129:8089"]	# 添加harbor服务器
}
[root@docker ~]# systemctl daemon-reload && systemctl restart docker	# 重启服务
[root@docker ~]# 

[root@docker ~]# docker pull 192.168.152.139:8089/sanchuang/nginx	#拉取镜像
Using default tag: latest
latest: Pulling from sanchuang/nginx
Digest: sha256:7f797701ded5055676d656f11071f84e2888548a2e7ed12a4977c28ef6114b17
Status: Downloaded newer image for 192.168.152.139:8089/sanchuang/nginx:latest
192.168.152.139:8089/sanchuang/nginx:latest

[root@docker ~]# docker images
REPOSITORY                             TAG            IMAGE ID       CREATED         SIZE
192.168.152.139:8089/sanchuang/nginx   latest         3f8a00f137a0   5 weeks ago     142MB

你可能感兴趣的:(Docker,docker,centos,linux)