私有仓库建立

docker pull registry

1、以下是显示下载完成信息

在这里插入图片描述

在这里插入代码片`[root@docker root5]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@docker root5]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
df9b9388f04a: Pull complete 
52dc419b0ee2: Pull complete 
b6846b9db566: Pull complete 
b0a23bbf973d: Pull complete 
c50f110701a7: Pull complete 
Digest: sha256:dc3cdf6d35677b54288fe9f04c34f59e85463ea7510c2a9703195b63187a7487
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
`

2、在docker 引擎终端设置

这里要先做一个镜像加速

[root@docker docker]# tee /etc/docker/daemon.json <<-'EOF'
> {
>   "registry-mirrors": ["https://jqqwsp8f.mirror.aliyuncs.com"]
> }
> EOF
{
  "registry-mirrors": ["https://jqqwsp8f.mirror.aliyuncs.com"]
}
[root@docker docker]# systemctl daemon-reload
[root@docker docker]# systemctl restart docker
[root@docker docker]# ls
daemon.json  key.json
[root@docker docker]# vim daemon.json
[root@docker docker]# systemctl daemon-reload 
[root@docker docker]# systemctl restart docker

在这里插入图片描述

vim /etc/docker/daemon.json
{
“insecure-registries”: [“192.168.10.41:5000”], //添加
“registry-mirrors”: [“https://05vz3np5.mirror.aliyuncs.com”]
}

systemctl restart docker.service

docker create -it registry /bin/bash

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f7497fcc8c2 registry “/entrypoint.sh /b…” 59 seconds ago Exited (2) 20 seconds ago musing_turing

[root@docker docker]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
registry     latest    2e200967d166   5 weeks ago   24.2MB
[root@docker docker]# docker create -it registry /bin/bash
9702b3ec209750cc93db305c521e3e81b6b1a974b7b69fb8ec3c327baadbc0d0
[root@docker docker]# docker ps -a
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS    PORTS     NAMES
9702b3ec2097   registry   "/entrypoint.sh /bin…"   10 seconds ago   Created             angry_chebyshev

在这里插入图片描述

3、是异常状态

docker start 6f7497fcc8c2

//宿主机的/data/registry自动创建挂载容器中的/tmp/registry
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry

[root@docker docker]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
822b4a132d27ffc62ffc38d7d01e1b04008198cf88107d853545435c2136e5d6
[root@docker docker]# docker ps -a
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                                       NAMES
822b4a132d27   registry   "/entrypoint.sh /etc…"   8 seconds ago   Up 7 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   jolly_engelbart
9702b3ec2097   registry   "/entrypoint.sh /bin…"   4 minutes ago   Created                                                    angry_chebyshev

在这里插入图片描述

//更改标记为192.168.10.41:5000/nginx
docker tag nginx:latest 192.168.10.41:5000/nginx

//上传
docker push 192.168.10.41:5000/nginx
在这里插入图片描述

[root@docker nginx_1]# docker tag nginx:1 192.168.10.41:5000/nginx:452
[root@docker nginx_1]# docker images
REPOSITORY                 TAG       IMAGE ID       CREATED          SIZE
192.168.10.41:5000/nginx   452       f9c2bacc8f4e   8 minutes ago    452MB
nginx                      1         f9c2bacc8f4e   8 minutes ago    452MB
<none>                     <none>    9e17f7e2878d   16 minutes ago   308MB
registry                   latest    2e200967d166   5 weeks ago      24.2MB
centos                     7         eeb6ee3f44bd   7 months ago     204MB
[root@docker nginx_1]# docker push 192.168.10.41:5000/nginx:452 
The push refers to repository [192.168.10.41:5000/nginx]
f7bb05718032: Pushed 
d7a1c6f32b5d: Pushed 
ef188e401bb1: Pushed 
022048f7bc0f: Pushed 
aaeca7b02c7a: Pushed 
741d7cdc7a1a: Pushed 
174f56854903: Pushed 
452: digest: sha256:9fdd30e1be465c857684238fc72716b6792e6654a9146db2c189056ea94b1fea size: 1788
[root@docker nginx_1]# curl -XGET http://192.168.10.41:5000/v2/_catalog
{"repositories":["nginx"]}

4、获取私有仓库列表

怎么获取registry的镜像仓库中的镜像信息
curl -XGET http://192.168.10.41:5000/v2/_catalog
在这里插入图片描述

//显示上传成功
{“repositories”:[“nginx”]}
在这里插入图片描述

5、测试私有仓库下载

docker pull 192.168.10.41:5000/nginx

Using default tag: latest
latest: Pulling from nginx
000eee12ec04: Pull complete
eb22865337de: Pull complete
bee5d581ef8b: Pull complete
Digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a
Status: Downloaded newer image for 192.168.10.41:5000/nginx:latest
192.168.10.41:5000/nginx:latest

二部署 Harbor 服务

Harbor 被部署为多个 Docker 容器,因此可以部署在任何支持 Docker 的 Linux 发行版 上。(registry 为其核心组件)
Harbor比registry相比好处是:harbor 支持多种功能、图形化界面管理、多用户权限、角色管理机制、安全机制
服务端主机需要安装 Python、Docker 和 Docker Compose。(web环境支持的是PY语言,故需要安装Python)

1.下载 Harbor 安装程序

wget http:// harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz

tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

2. 配置 Harbor 参数文件

vim /usr/local/harbor/harbor.cfg
hostname = 192.168.10.41

[root@docker harbor]# vim harbor.cfg 

  1 ## Configuration file of Harbor
  2 
  3 #The IP address or hostname to access admin UI and registry se    rvice.
  4 #DO NOT use localhost or 127.0.0.1, because Harbor needs to be     accessed by external clients.
  5 hostname = 192.168.1041

在这里插入图片描述

关于 Harbor.cfg 配置文件中有两类参数:所需参数和可选参数

(1)所需参数 这些参数需要在配置文件 Harbor.cfg 中设置


如果用户更新它们并运行 install.sh脚本重新安装 Harbor,
参数将生效。具体参数如下:

hostname:用于访问用户界面和 register 服务。它应该是目标机器的 IP 地址或完全限 定的域名(FQDN)
例如 192.168.226.130 或 hub.kgc.cn。不要使用 localhost 或 127.0.0.1 为主机名。

ui_url_protocol:(http 或 https,默认为 http)用于访问 UI 和令牌/通知服务的协议。如果公证处于启用状态,则此参数必须为 https。(身份验证时会向Mysql数据库进行比对,然后授予令牌)

max_job_workers:镜像复制作业线程。

db_password:用于db_auth 的MySQL数据库root 用户的密码。

customize_crt:该属性可设置为打开或关闭,默认打开。打开此属性时,准备脚本创建私钥和根证书,用于生成/验证注册表令牌。
当由外部来源提供密钥和根证书时,将此属性设置为 off。

ssl_cert:SSL 证书的路径,仅当协议设置为 https 时才应用。

ssl_cert_key:SSL 密钥的路径,仅当协议设置为 https 时才应用。

secretkey_path:用于在复制策略中加密或解密远程 register 密码的密钥路径。

(2)可选参数

这些参数对于更新是可选的,即用户可以将其保留为默认值,并在启动 Harbor 后在 Web UI 上进行更新。
如果进入 Harbor.cfg,只会在第一次启动 Harbor 时生效,随后对这些参数的更新,Harbor.cfg 将被忽略。

注意:如果选择通过UI设置这些参数,请确保在启动Harbour后立即执行此操作。具体来说,必须在注册或在 Harbor 中创建任何新用户之前设置所需的
auth_mode。当系统中有用户时(除了默认的 admin 用户),auth_mode 不能被修改。具体参数如下:

Email:Harbor需要该参数才能向用户发送“密码重置”电子邮件,并且只有在需要该功能时才需要。
请注意,在默认情况下SSL连接时没有启用。如果SMTP服务器需要SSL,但不支持STARTTLS,那么应该通过设置启用SSL email_ssl = TRUE。

harbour_admin_password:管理员的初始密码,只在Harbour第一次启动时生效。之后,此设置将被忽略,并且应 UI中设置管理员的密码。
请注意,默认的用户名/密码是 admin/Harbor12345。

auth_mode:使用的认证类型,默认情况下,它是 db_auth,即凭据存储在数据库中。对于LDAP身份验证(以文件形式验证),请将其设置为 ldap_auth。

self_registration:启用/禁用用户注册功能。禁用时,新用户只能由 Admin 用户创建,只有管理员用户可以在 Harbour中创建新用户。
注意:当 auth_mode 设置为 ldap_auth 时,自注册功能将始终处于禁用状态,并且该标志被忽略。

Token_expiration:由令牌服务创建的令牌的到期时间(分钟),默认为 30 分钟。

project_creation_restriction:用于控制哪些用户有权创建项目的标志。默认情况下, 每个人都可以创建一个项目。
如果将其值设置为“adminonly”,那么只有 admin 可以创建项目。

verify_remote_cert:打开或关闭,默认打开。此标志决定了当Harbor与远程 register 实例通信时是否验证 SSL/TLS 证书。
将此属性设置为 off 将绕过 SSL/TLS 验证,这在远程实例具有自签名或不可信证书时经常使用。

另外,默认情况下,Harbor 将镜像存储在本地文件系统上。在生产环境中,可以考虑使用其他存储后端而不是本地文件系统,
如 S3、Openstack Swif、Ceph 等。但需要更新 common/templates/registry/config.yml 文件。

3. 启动 Harbor

sh /usr/local/harbor/install.sh
在这里插入图片描述
#####下面这是查看harbor.v1.2.2.tar.gz里面的内容(不用做这一步操作)
在这里插入图片描述
在这里插入图片描述

4. 查看 Harbor 启动镜像

//查看镜像
docker images
在这里插入图片描述
//查看容器

docker ps -a
在这里插入图片描述
cd /usr/local/harbor/
docker-compose ps

在这里插入图片描述
如果一切都正常,应该可以打开浏览器访问 http://192.168.10.41 的管理页面,默认 的管理员用户名和密码是 admin/Harbor12345。
在这里插入图片描述
在这里插入图片描述
//添加项目并且填写项目名称

在这里插入图片描述

在这里插入图片描述
此时可使用 Docker 命令在本地通过 127.0.0.1 来登录和推送镜像。默认情况下,
Register 服务器在端口 80 上侦听.

//登录
docker login -u admin -p Harbor12345 http://127.0.0.1

//下载镜像进行测试
docker pull cirros

//镜像打标签
docker tag cirros 127.0.0.1/myproject-kgc/cirros:v1

//上传镜像到Harbor
docker push 127.0.0.1/myproject-kgc/cirros:v1

在这里插入图片描述

以上操作都是在 Harbor 服务器本地操作。如果其他客户端上传镜像到 Harbor,就会报
如下错误。出现这问题的原因 Docker Registry 交互默认使用的是 HTTPS,但是搭建私有镜
像默认使用的是 HTTP 服务,所以与私有镜像交互时出现以下错误。

[root@client ~]# docker login -u admin -p Harbor12345 http://192.168.10.41
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.10.41/v2/: EOF

//解决:
[root@client ~]# vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.10.41 --containerd=/run/containerd/containerd.sock

[root@client ~]# systemctl daemon-reload
[root@client ~]# systemctl restart docker
[root@client ~]# docker login -u admin -p Harbor12345 http://192.168.10.41
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
在这里插入图片描述

[root@client ~]# docker pull cirros
Using default tag: latest
latest: Pulling from library/cirros
3d6427f49fe3: Pull complete
1915bfe8159b: Pull complete
d0ec9ef25b96: Pull complete
Digest: sha256:8654d33ecbcdc8fd65c80325c3ec3b1bc938dfad9f20d1a2e3cf21e521ab70e6
Status: Downloaded newer image for cirros:latest
docker.io/library/cirros:latest
在这里插入图片描述

[root@docker yum.repos.d]# docker pull cirros
Using default tag: latest
latest: Pulling from library/cirros
d0b405be7a32: Pull complete 
bd054094a037: Pull complete 
c6a00de1ec8a: Pull complete 
Digest: sha256:7b3e8db2c7501cdbf4b670335bbea911e30a21d502b4b0c179f6efc7912281b2
Status: Downloaded newer image for cirros:latest
docker.io/library/cirros:latest
[root@docker yum.repos.d]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
cirros       latest    f9cae1daf5f6   14 months ago   12.6MB

[root@client ~]# docker tag cirros 192.168.10.41/myproject/cirros:v2

[root@client ~]# docker push 192.168.10.41/myproject/cirros:v2
The push refers to repository [192.168.10.41/myproject/cirros]
abbd6d6ac643: Layer already exists
75b99987219d: Layer already exists
0cc237193a30: Layer already exists
v2: digest: sha256:96137d51e0e46006243fa2403723eb47f67818802d1175b5cde7eaa7f19446bd size: 943
在这里插入图片描述

在这里插入图片描述

5.维护管理Harbor

可以使用 docker-compose 来管理 Harbor。一些有用的命令如下所示,必须在与
docker-compose.yml 相同的目录中运行。

修改 Harbor.cfg 配置文件
要更改 Harbour 的配置文件时,请先停止现有的 Harbour 实例并更新 Harbor.cfg;然
后运行 prepare 脚本来填充配置;最后重新创建并启动 Harbour 的实例。

docker-compose down -v
Stopping nginx … done
Stopping harbor-jobservice … done
Stopping harbor-ui … done
Stopping harbor-adminserver … done
Stopping harbor-db … done
Stopping registry … done
Stopping harbor-log … done
Removing nginx … done
Removing harbor-jobservice … done
Removing harbor-ui … done
Removing harbor-adminserver … done
Removing harbor-db … done
Removing registry … done
Removing harbor-log … done
Removing network harbor_harbor

vim harbor.cfg

./prepare
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/app.conf
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/nginx.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.

//报错:
docker-compose up -d
Creating network “harbor_harbor” with the default driver
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-25094fc09b3c -j RETURN: iptables: No chain/target/match by that name.
(exit status 1))
//解决:关闭防火墙后,docker需要重启
systemctl restart docker
docker-compose up -d
Creating network “harbor_harbor” with the default driver
Creating harbor-log … done
Creating harbor-db … done
Creating harbor-adminserver … done
Creating registry … done
Creating harbor-ui … done
Creating harbor-jobservice … done
Creating nginx … done

6.创建 Harbor 用户

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

7.创建项目开发人员

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
//在客户端上操作
[root@client ~]# docker rmi 192.168.10.418/myproject/cirros:v2
Untagged: 192.168.10.41/myproject/cirros:v2
Untagged: 192.168.10.41/myproject/cirros@sha256:96137d51e0e46006243fa2403723eb47f67818802d1175b5cde7eaa7f19446bd
//注销登录
[root@client ~]# docker logout 192.168.1041
Removing login credentials for 192.168.10.41

[root@client ~]# docker login 192.168.10.41
Username: pdada
Password: //填写Harbor1234
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@client ~]# docker pull 192.168.10.418/myproject/cirros:v1
v1: Pulling from myproject-kgc/cirros
Digest: sha256:96137d51e0e46006243fa2403723eb47f67818802d1175b5cde7eaa7f19446bd
Status: Downloaded newer image for 192.168.10.41/myproject-kgc/cirros:v1
192.168.195.128/myproject-kgc/cirros:v1
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.195.128/myproject-kgc/cirros v1 bc94bceaae77 11 months ago 10.3MB
cirros latest bc94bceaae77 11 months ago 10.3MB

移除 Harbor 服务容器同时保留镜像数据/数据库
//在Harbor服务器上操作
docker-compose down -v
Stopping nginx … done
Stopping harbor-jobservice … done
Stopping harbor-ui … done
Stopping registry … done
Stopping harbor-db … done
Stopping harbor-adminserver … done
Stopping harbor-log … done
Removing nginx … done
Removing harbor-jobservice … done
Removing harbor-ui … done
Removing registry … done
Removing harbor-db … done
Removing harbor-adminserver … done
Removing harbor-log … done
Removing network harbor_harbor
如需重新部署,需要移除 Harbor 服务容器全部数据
持久数据,如镜像,数据库等在宿主机的/data/目录下,日志在宿主机的
/var/log/Harbor/目录下。
rm -rf /data/database/
rm -rf /data/registry/

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值