![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/888b4fb23c1945f1a8cb4c720194d1e8.jpeg)
概要
构建一个带有用户界面(UI)的本地Docker镜像仓库,你可以使用一些现成的工具,如Harbor、Sonatype Nexus或JFrog Artifactory。这些工具提供了一个完整的解决方案,包括用户界面、认证、访问控制、镜像管理等特性。
以下是使用Harbor作为示例来构建带有UI的本地Docker镜像仓库的步骤:
安装Harbor
-
下载Harbor
- 访问Harbor的官方GitHub页面,下载适合你操作系统的安装包。下面使用
wget
下载v2.3.3
版本wget https://github.com/goharbor/harbor/releases/download/<version>/harbor-offline-installer-<version>.tgz
- 访问Harbor的官方GitHub页面,下载适合你操作系统的安装包。下面使用
-
解压Harbor
- 解压下载的Harbor安装包。
tar -zxvf harbor-offline-installer-<version>.tgz cd harbor
- 解压下载的Harbor安装包。
-
配置Harbor
-
修改配置文件名字。
mv harbor.yml.tmpl harbor.yml
-
在
harbor
目录下,vim编辑harbor.yml
配置文件,配置你的仓库的端口、数据库、存储等信息。https认证全部注释掉
。...... hostname: <宿主机IP> # http related config http: # port for http, default is 80. If https enabled, this port will redirect to https port port: 80 #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 ......
-
-
安装Harbor
- 使用提供的安装脚本安装Harbor。
sudo sh install.sh
- 使用提供的安装脚本安装Harbor。
-
启动Harbor
- 安装完成后,Harbor会自动启动。
- 手动启停
#切换到harbor目录 cd harbor #停止harbor容器 docker-compose down -v # 启动harbor容器 docker-compose up -d
-
登录Harbor UI
- 你可以通过访问
http://<your-ip>
来查看Harbor的Web UI。 - 使用默认的管理员账户(用户名:
admin
,密码:Harbor12345
)登录Harbor的Web UI。
- 你可以通过访问
-
配置 Docker 信任地址
- 因为Habor采用的是 HTTP 协议,默认不被 Docker 信任,需要进行配置。编辑 Docker 守护进程配置文件
/etc/docker/daemon.json
增加"insecure-registries": ["http://<宿主机IP>:80"]
, 如下所示:
其它参数解释参考Docker和Docker-Compose安装。{ "registry-mirrors": [ "https://registry.cn-beijing.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn/" ], "insecure-registries": ["http://<宿主机IP>:80"], "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "data-root": "/data/docker", "storage-driver": "overlay2" }
- 重载 Docker 守护进程配置并重启 Docker
systemctl daemon-reload systemctl restart docker
- 因为Habor采用的是 HTTP 协议,默认不被 Docker 信任,需要进行配置。编辑 Docker 守护进程配置文件
-
Docker客户端登录Harbor
- 配置Docker客户端以使用你的Harbor仓库作为默认仓库。
docker login <your-ip>:80
- 根据提示输入用户名:
admin
和 密码:Harbor12345
- 配置Docker客户端以使用你的Harbor仓库作为默认仓库。
-
推送镜像到Harbor
-
使用下面的命令将你的Docker镜像推送到Harbor。
docker tag your-image <your-ip>:80/<项目名>/your-image docker push <your-ip>:80/<项目名>/your-image
-
示例
docker pull busybox docker tag busybox 192.168.44.161:80/test/busybox:first docker push 192.168.44.161:80/test/busybox:first
Harbor会根据
<your-ip>:80/<项目名>
来锁定推送的仓库地址。默认推送的仓库地址是docker.io
。
-
-
从Harbor拉取镜像
- 拉取镜像
docker pull <your-ip>:80/<<项目名>/your-image>
- 拉取镜像
-
管理仓库
- 通过Harbor的Web UI,你可以管理仓库、用户、项目等。