Docker 学习笔记-03:镜像提交及发布(公有仓库 & 私有仓库 Harbor)

本文详细介绍了Harbor镜像的加载原理、分层特性、容器层的使用,以及镜像的提交、发布(包括公有和私有)流程。重点讲解了Harbor的架构、部署步骤和配置,以及如何在Harbor平台上进行镜像的上传下载操作。
摘要由CSDN通过智能技术生成

镜像

镜像,是一种轻量级的、可执行的独立软件包,包含运行某个软件所需要的所有内容。(应用程序和配置打包好形成一个可交付的运行环境【包含代码、运行库、环境变量、配置文件等】)

分层镜像

[root@localhost ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0e29546d541c: Pull complete 
9b829c73b52b: Pull complete 
cb5b7ae36172: Pull complete 
6494e4811622: Pull complete 
668f6fcc5fa5: Pull complete 
dc120c3e0290: Pull complete 
8f7c0eebb7b1: Pull complete 
77b694f83996: Pull complete 
0f611256ec3a: Pull complete 
4f25def12f23: Pull complete 
Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest

联合文件系统 UnionFS

UnionFS 是一种分层、轻量级且高性能的文件系统,支持对文件系统的修改作为一次提交来一层层叠加,同时可以将不同目录挂载到统一个虚拟文件系统下。Union 文件系统是 Docker 镜像的基础。镜像可以通过分层来进行集成,基于基础镜像(模板概念,无父镜像)可以制作各种各样的应用镜像。

镜像加载原理

在这里插入图片描述


bootfs(Docker 镜像底层),主要包含 BootLoader(引导加载 Kernel) 和 Kernel。linux 启动时会加载 bootfs 文件系统。【BootLoader 加载完成之后,会卸载 bootfs,之后会通过 Kernel 执行下述操作】
rootfs(操作系统发行版),在 bootfs 之上,包含典型的 linux 的标准目录和文件。精简的OS,rootfs 可以很小,仅包含基础的命名、工具和库。

镜像容器层

在这里插入图片描述

  • 镜像层:只读
  • 容器层:当容器启动时,一个新的可写层将被添加到容器的顶部(即:容器层)

镜像提交发布

Docker通过镜像分层,支持拓展现有镜像,创建新的镜像(按需叠加镜像层)

镜像提交

docker commit -m="commit message" -a="author" [containerID or containerName] userName/imageName:tag

镜像发布(公有)

以阿里云为例,需要登录阿里云并开通镜像仓库服务,按照页面操作即可

# 登录镜像仓库
docker login --username=xxxx registry.cn-hangzhou.aliyuncs.com
# 标记本地镜像
docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/namespace/registry:[镜像版本号]
# 推送镜像到远程仓库
docker push registry.cn-hangzhou.aliyuncs.com/namespace/registry:[镜像版本号]
# 拉取远程仓库镜像
docker pull registry.cn-hangzhou.aliyuncs.com/namespace/registry:[镜像版本号]

镜像发布(私有,Harbor)

VMware开源的企业级Registry项目Harbor,以Docker公司开源的registry为基础,提供了管理UI, 基于角色的访问控制(Role Based Access Control),AD/LDAP集成、以及审计日志(Audit logging) 等企业用户需求的功能。

Harbor架构

客户端请求都经过Proxy代理组件,通过转发给Core servicesRegistry,其中Core services包括UI界面、token令牌和webhook网页服务功能,Registry主要提供镜像存储功能。
如果要进行下载上传镜像,要经过token令牌验证然后从Registry获取或上传镜像,每一次下载或上传都会生成日志记录,会记入Log collector,而用户身份权限及一些镜像语言信息会被存储在Database中,Job services主要用于镜像复制,本地镜像可以被同步到远程Harbor实例上。
在这里插入图片描述

[root@VM-8-2-centos ~]# docker ps | grep harbor
0371e5284c84        goharbor/nginx-photon:v2.5.0         "nginx -g 'daemon of…"   4 weeks ago         Up 4 weeks (healthy)   0.0.0.0:7777->8080/tcp      nginx
c8bd5f1e2730        goharbor/harbor-jobservice:v2.5.0    "/harbor/entrypoint.…"   4 weeks ago         Up 4 weeks (healthy)                               harbor-jobservice
207ebb39c4c5        goharbor/harbor-core:v2.5.0          "/harbor/entrypoint.…"   4 weeks ago         Up 4 weeks (healthy)                               harbor-core
cadcf86ee55e        goharbor/harbor-db:v2.5.0            "/docker-entrypoint.…"   4 weeks ago         Up 4 weeks (healthy)                               harbor-db
e93db2acda02        goharbor/registry-photon:v2.5.0      "/home/harbor/entryp…"   4 weeks ago         Up 4 weeks (healthy)                               registry
ee885c1abc04        goharbor/harbor-registryctl:v2.5.0   "/home/harbor/start.…"   4 weeks ago         Up 4 weeks (healthy)                               registryctl
d44ac8fbff91        goharbor/redis-photon:v2.5.0         "redis-server /etc/r…"   4 weeks ago         Up 4 weeks (healthy)                               redis
1bb44196e866        goharbor/harbor-portal:v2.5.0        "nginx -g 'daemon of…"   4 weeks ago         Up 4 weeks (healthy)                               harbor-portal
f00cfcf59295        goharbor/harbor-log:v2.5.0           "/bin/sh -c /usr/loc…"   4 weeks ago         Up 4 weeks (healthy)   127.0.0.1:1514->10514/tcp   harbor-log

Harbor部署

环境检查
[root@VM-8-2-centos ~]# docker -v
Docker version 19.03.9, build 9d988398e7
[root@VM-8-2-centos ~]# uname -a
Linux VM-8-2-centos 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@VM-8-2-centos ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

准备工作

安装并升级 python pip

[root@VM-8-2-centos ~]# yum install python-pip -y
[root@VM-8-2-centos ~]# pip3 install --upgrade pip

安装并查看docker-compose

[root@VM-8-2-centos ~]# pip3 install docker-compose
[root@VM-8-2-centos ~]# docker-compose -v
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.hazmat.backends import default_backend
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,
docker-compose version 1.29.2, build unknown

安装Harbor

下载harbor安装包:https://github.com/goharbor/harbor/releases,并上传服务器,以 2.5.0 为例
在这里插入图片描述


解压harbor安装包

[root@VM-8-2-centos packages]# ls 
harbor-offline-installer-v2.5.0.tgz
[root@VM-8-2-centos packages]# tar xf harbor-offline-installer-v2.5.0.tgz 
[root@VM-8-2-centos packages]# cd harbor/
[root@VM-8-2-centos harbor]# ls
common.sh  harbor.v2.5.0.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare

修改harbor.yml配置文件

[root@VM-8-2-centos harbor]# cp harbor.yml.tmpl harbor.yml
[root@VM-8-2-centos harbor]# vim harbor.yml
  • hostname:访问地址
  • port:访问端口,默认80
  • harbor_admin_password:admin账户密码,默认Harbor12345
  • data_volume:数据卷存储位置,默认/data
  • 其他可根据需要进行配置

运行初始化脚本,harbor会导入镜像并启动容器

[root@VM-8-2-centos harbor]# ./install.sh 

[Step 0]: checking if docker is installed ...

Note: docker version: 19.03.9

[Step 1]: checking docker-compose is installed ...
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.hazmat.backends import default_backend
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,

Note: docker-compose version: 1.29.2

[Step 2]: loading Harbor images ...
2728eced976d: Loading layer [==================================================>]  37.53MB/37.53MB
cc3b18252fc8: Loading layer [==================================================>]  8.682MB/8.682MB
e27442ada648: Loading layer [==================================================>]  3.584kB/3.584kB
510fffdc5915: Loading layer [==================================================>]   2.56kB/2.56kB
30467ddcf6f2: Loading layer [==================================================>]  78.68MB/78.68MB
7e04a5612589: Loading layer [==================================================>]  5.632kB/5.632kB
0ac0247e2d58: Loading layer [==================================================>]  99.84kB/99.84kB
420bc1ee1df5: Loading layer [==================================================>]  15.87kB/15.87kB
cc2bd615d6c2: Loading layer [==================================================>]  79.59MB/79.59MB
f10b6ae8e460: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.5.0
2c3687cd3c96: Loading layer [==================================================>]  8.682MB/8.682MB
ffaf1e983398: Loading layer [==================================================>]  3.584kB/3.584kB
6dca51eebde6: Loading layer [==================================================>]   2.56kB/2.56kB
e4bbd379d36f: Loading layer [==================================================>]  90.73MB/90.73MB
0c5623dfd7c8: Loading layer [==================================================>]  91.52MB/91.52MB
Loaded image: goharbor/harbor-jobservice:v2.5.0
6693dd6cc84d: Loading layer [==================================================>]  5.535MB/5.535MB
3a46d81a0f15: Loading layer [==================================================>]  8.543MB/8.543MB
1e10a48739ea: Loading layer [==================================================>]  14.47MB/14.47MB
b54aab661800: Loading layer [==================================================>]  29.29MB/29.29MB
8f500c8fb731: Loading layer [==================================================>]  22.02kB/22.02kB
15fdd079b41a: Loading layer [==================================================>]  14.47MB/14.47MB
Loaded image: goharbor/notary-signer-photon:v2.5.0
06b7933f92b4: Loading layer [==================================================>]  1.097MB/1.097MB
69fae5574072: Loading layer [==================================================>]  5.889MB/5.889MB
af3112c929b0: Loading layer [==================================================>]    168MB/168MB
03f5f7cbe3a7: Loading layer [==================================================>]  16.27MB/16.27MB
61c47e73996b: Loading layer [==================================================>]  4.096kB/4.096kB
ca3b66c3cab8: Loading layer [==================================================>]  6.144kB/6.144kB
94865dea6411: Loading layer [==================================================>]  3.072kB/3.072kB
2c98011427ba: Loading layer [==================================================>]  2.048kB/2.048kB
b497970298a9: Loading layer [==================================================>]   2.56kB/2.56kB
3b6f7dbc8aef: Loading layer [==================================================>]   2.56kB/2.56kB
2e79a86e0f4c: Loading layer [==================================================>]   2.56kB/2.56kB
9a01f04243a5: Loading layer [==================================================>]  8.704kB/8.704kB
Loaded image: goharbor/harbor-db:v2.5.0
826c5dd08e02: Loading layer [==================================================>]   5.54MB/5.54MB
7c9c7bdcf444: Loading layer [==================================================>]  4.096kB/4.096kB
f223cbf045aa: Loading layer [==================================================>]  17.32MB/17.32MB
38956705c7f1: Loading layer [==================================================>]  3.072kB/3.072kB
99a84179e4ff: Loading layer [==================================================>]  29.12MB/29.12MB
acbe177c3da5: Loading layer [==================================================>]  47.23MB/47.23MB
Loaded image: goharbor/harbor-registryctl:v2.5.0
a04b11a8a6ee: Loading layer [==================================================>]    122MB/122MB
5fd3685787a9: Loading layer [==================================================>]  3.072kB/3.072kB
4ee52d1501b6: Loading layer [==================================================>]   59.9kB/59.9kB
cfcae3e40a56: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.5.0
95de1218b455: Loading layer [==================================================>]  7.453MB/7.453MB
0332b27525fd: Loading layer [==================================================>]  7.362MB/7.362MB
2b702d470d2f: Loading layer [==================================================>]      1MB/1MB
Loaded image: goharbor/harbor-portal:v2.5.0
16ab1b0f6423: Loading layer [==================================================>]  6.067MB/6.067MB
71741b9e40d6: Loading layer [==================================================>]  4.096kB/4.096kB
b6227c4d071e: Loading layer [==================================================>]  3.072kB/3.072kB
ce0427bdf83d: Loading layer [==================================================>]  47.85MB/47.85MB
2e2a73e9bf05: Loading layer [==================================================>]  12.38MB/12.38MB
ec1590e149e7: Loading layer [==================================================>]  61.02MB/61.02MB
Loaded image: goharbor/trivy-adapter-photon:v2.5.0
c91db62634c3: Loading layer [==================================================>]  7.453MB/7.453MB
Loaded image: goharbor/nginx-photon:v2.5.0
d7cf625fc9a4: Loading layer [==================================================>]   5.54MB/5.54MB
b451f0ec0b7a: Loading layer [==================================================>]  4.096kB/4.096kB
b88e800d533f: Loading layer [==================================================>]  3.072kB/3.072kB
db6daabbcca3: Loading layer [==================================================>]  17.32MB/17.32MB
695d78a7189a: Loading layer [==================================================>]  18.12MB/18.12MB
Loaded image: goharbor/registry-photon:v2.5.0
89c925538f60: Loading layer [==================================================>]  5.535MB/5.535MB
e4324e4ca305: Loading layer [==================================================>]  8.543MB/8.543MB
81fb5fe866e7: Loading layer [==================================================>]  15.88MB/15.88MB
d7a351be6527: Loading layer [==================================================>]  29.29MB/29.29MB
1a27b90552b4: Loading layer [==================================================>]  22.02kB/22.02kB
9cbf49e39556: Loading layer [==================================================>]  15.88MB/15.88MB
Loaded image: goharbor/notary-server-photon:v2.5.0
d157647932aa: Loading layer [==================================================>]  5.539MB/5.539MB
47c8814697b5: Loading layer [==================================================>]  90.86MB/90.86MB
101c95239656: Loading layer [==================================================>]  3.072kB/3.072kB
ab57dc233b33: Loading layer [==================================================>]  4.096kB/4.096kB
a5fa5daa44ac: Loading layer [==================================================>]  91.65MB/91.65MB
Loaded image: goharbor/chartmuseum-photon:v2.5.0
c7b58a7cc092: Loading layer [==================================================>]  167.8MB/167.8MB
b3dc882c87d2: Loading layer [==================================================>]  67.83MB/67.83MB
d84728b46c3d: Loading layer [==================================================>]   2.56kB/2.56kB
b2451fcf6b6e: Loading layer [==================================================>]  1.536kB/1.536kB
c0d555c98da7: Loading layer [==================================================>]  12.29kB/12.29kB
2bf34ea57de3: Loading layer [==================================================>]  2.621MB/2.621MB
77c438a147df: Loading layer [==================================================>]  354.8kB/354.8kB
Loaded image: goharbor/prepare:v2.5.0
79d6933e24a3: Loading layer [==================================================>]  126.1MB/126.1MB
3488b7bd8881: Loading layer [==================================================>]  3.584kB/3.584kB
7c322822684a: Loading layer [==================================================>]  3.072kB/3.072kB
3a1942a8665c: Loading layer [==================================================>]   2.56kB/2.56kB
68dc95a925af: Loading layer [==================================================>]  3.072kB/3.072kB
f5ad41459af9: Loading layer [==================================================>]  3.584kB/3.584kB
fcf472032de4: Loading layer [==================================================>]  20.99kB/20.99kB
Loaded image: goharbor/harbor-log:v2.5.0
c548f6088999: Loading layer [==================================================>]  8.682MB/8.682MB
cca18a30887f: Loading layer [==================================================>]  20.98MB/20.98MB
0625337d71b6: Loading layer [==================================================>]  4.608kB/4.608kB
65af3866d520: Loading layer [==================================================>]  21.77MB/21.77MB
Loaded image: goharbor/harbor-exporter:v2.5.0


[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /home/jiangyf/packages/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir

/usr/local/lib/python3.6/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.hazmat.backends import default_backend
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,


[Step 5]: starting Harbor ...
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.hazmat.backends import default_backend
/usr/local/lib/python3.6/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-db     ... done
Creating registryctl   ... done
Creating redis         ... done
Creating harbor-portal ... done
Creating registry      ... done
Creating harbor-core   ... done
Creating harbor-jobservice ... done
Creating nginx             ... done
✔ ----Harbor has been installed and started successfully.----

查看harbor相关容器运行情况

[root@VM-8-2-centos harbor]# docker ps -q
0371e5284c84
c8bd5f1e2730
207ebb39c4c5
cadcf86ee55e
e93db2acda02
ee885c1abc04
d44ac8fbff91
1bb44196e866
f00cfcf59295

浏览器访问harbor管理页面,注意开通端口放行,根据配置文件中填写的

在这里插入图片描述

上传下载镜像(同公有发布)

登录私有Harbor仓库,由于配置私有仓库时未开启https访问,而Docker默认的仓库交互方式为https,因此需要添加insecure-registries/etc/docker/daemon.json文件中,添加完成后重新启动Docker重新登录即可进行镜像的committagpushpull操作。

[root@localhost ~]# docker login xxxxx:xxxx
Username: xxxx
Password: 
Error response from daemon: Get "https://xxxxx:xxxx/v2/": http: server gave HTTP response to HTTPS client
[root@localhost ~]# vim /etc/docker/daemon.json 
[root@localhost ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://xxxxxxxxxx.mirror.aliyuncs.com"],
  "insecure-registries":["xxxxx:xxxx"]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程小透明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值