阿里云 kubernetes 容器 【Docker】Docker Harbor的安装和使用案例——上传自己的镜像(Ubuntu实例)到自己的镜像仓库(Harbor) - [root@nfs docker]# docker images

📅 2026-11-30 👤 拼多多助力营销技巧 📂 2027拼多多助力 👁️ 317 次阅读

文章目录

1. 提前条件2. 下载Harbor源码3. 从Windows上传到linux服务器并解压4. 调整配置4.1 从.yml.tmpl拷贝一份.yml文件[root@JD30-aliyun harbor]# cp harbor.yml.tmpl harbor.yml4.2 修改harbor.yml文件

5. 安装6. 在windows机器上访问网站,去配置harbor7. 上传镜像到Harbor7.1 在另外一台docker宿主机上使用这个仓库7.2 弄一个新的ubuntu的镜像7.3 修改镜像的名字7.4 登录使用admin这个用户7.5 把镜像push到Harbor上7.6 查看自己的镜像仓库

8. 测试,删除本机的镜像,去仓库里拉取8.1 删除本机的镜像8.2 拉取自己仓库里的镜像(刚刚上传的ubuntu)8.3 查看本机的镜像

1. 提前条件

安装好Docker和Docker Compose并启动好。本次实验环境是在阿里云服务器上操作。 Ali Cloud ECS 配置如图: 安装好Docker和Docker Compose后查看是否安装成功:

2. 下载Harbor源码

若要下载最新版或者其他版本,可到官方文档或者github: https://goharbor.io/docs/2.7.0/install-config/download-installer/

https://github.com/goharbor/harbor/releases/

我这里就下载Harbor v2.1.0 要是官网或者github上下载慢的话,我提供一个百度网盘: 链接:https://pan.baidu.com/s/1ir526Teht9-Q5IaREI3kug 提取码:yjih 复制这段内容后打开百度网盘手机App,操作更方便chuanshu 拼多多帮助力入口

3. 从Windows上传到linux服务器并解压

创建目录/root/harbor

[root@JD30-aliyun ~]# mkdir harbor

[root@JD30-aliyun ~]# cd harbor

[root@JD30-aliyun harbor]#

传输 解压:

[root@JD30-aliyun harbor]# ls

harbor-offline-installer-v2.1.0.tgz

[root@JD30-aliyun harbor]# tar xf harbor-offline-installer-v2.1.0.tgz

[root@JD30-aliyun harbor]# ls

harbor harbor-offline-installer-v2.1.0.tgz

[root@JD30-aliyun harbor]# cd harbor

[root@JD30-aliyun harbor]# ls

common.sh harbor.v2.1.0.tar.gz harbor.yml.tmpl install.sh LICENSE prepare

[root@JD30-aliyun harbor]# ll

total 545268

-rw-r--r-- 1 root root 3361 Sep 16 2020 common.sh

-rw-r--r-- 1 root root 558317240 Sep 16 2020 harbor.v2.1.0.tar.gz

-rw-r--r-- 1 root root 8136 Sep 16 2020 harbor.yml.tmpl

-rwxr-xr-x 1 root root 2523 Sep 16 2020 install.sh

-rw-r--r-- 1 root root 11347 Sep 16 2020 LICENSE

-rwxr-xr-x 1 root root 1881 Sep 16 2020 prepare

[root@JD30-aliyun harbor]#

注意当前路径:

4. 调整配置

4.1 从.yml.tmpl拷贝一份.yml文件[root@JD30-aliyun harbor]# cp harbor.yml.tmpl harbor.yml

[root@JD30-aliyun harbor]# ll

total 545276

-rw-r--r-- 1 root root 3361 Sep 16 2020 common.sh

-rw-r--r-- 1 root root 558317240 Sep 16 2020 harbor.v2.1.0.tar.gz

-rw-r--r-- 1 root root 8136 Mar 14 13:49 harbor.yml

-rw-r--r-- 1 root root 8136 Sep 16 2020 harbor.yml.tmpl

-rwxr-xr-x 1 root root 2523 Sep 16 2020 install.sh

-rw-r--r-- 1 root root 11347 Sep 16 2020 LICENSE

-rwxr-xr-x 1 root root 1881 Sep 16 2020 prepare

4.2 修改harbor.yml文件

修改了:hostname: 8.130.33.145 和 port: 8089;

注释掉了https的配置;

其他的配置没有修改。

vim harbor.yml

5. 安装

给install.sh可执行权限,并且将其脚本里的"docker-compose"改成"docker compose"。注意还有一个地方,在脚本前就能看到,一定要改common.sh,把这里面的"docker-compose"改成"docker compose"就改完全了~

执行./install.sh

[root@JD30-aliyun harbor]# ./install.sh

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

Note: docker version: 23.0.1

[Step 1]: checking docker compose is installed ...

Note: docker compose version: 2.16.0

[Step 2]: loading Harbor images ...

✔ ----Harbor has been installed and started successfully.----

查看,启动了一些容器:

6. 在windows机器上访问网站,去配置harbor

访问:8.130.33.145:8089登录harbor 默认的登录的用户名和密码 admin Harbor12345新建项目 新建项目 jd

7. 上传镜像到Harbor

7.1 在另外一台docker宿主机上使用这个仓库

[root@nfs yum.repos.d]# cd /etc/docker/ [root@nfs docker]# ls [root@nfs docker]# vim daemon.json

{

"registry-mirrors": ["https://registry.docker-cn.com"],

"insecure-registries" : ["8.130.33.145:8089"]

}

然后重启docker:

[root@nfs docker]# systemctl daemon-reload

[root@nfs docker]# systemctl restart docker

[root@nfs docker]#

7.2 弄一个新的ubuntu的镜像

从官方拉取ubuntu镜像和查看:

[root@nfs docker]# docker pull ubuntu

Using default tag: latest

latest: Pulling from library/ubuntu

76769433fd8a: Pulling fs layer

76769433fd8a: Pull complete

Digest: sha256:2adf22367284330af9f832ffefb717c78239f6251d9d0f58de50b86229ed1427

Status: Downloaded newer image for ubuntu:latest

docker.io/library/ubuntu:latest

[root@nfs docker]#

[root@nfs docker]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

ubuntu latest 74f2314a03de 13 days ago 77.8MB

7.3 修改镜像的名字

给镜像打标签,标记本地镜像,将其归入某一仓库,也就是Harbor里的路径。 执行:docker tag ubuntu 8.130.33.145:8089/jd/ubuntu

[root@nfs docker]# docker tag ubuntu 8.130.33.145:8089/jd/ubuntu

[root@nfs docker]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

8.130.33.145:8089/jd/ubuntu latest 74f2314a03de 13 days ago 77.8MB

ubuntu latest 74f2314a03de 13 days ago 77.8MB

7.4 登录使用admin这个用户

[root@nfs docker]# docker login 8.130.33.145:8089

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@nfs docker]#

7.5 把镜像push到Harbor上

执行:docker push 8.130.33.145:8089/jd/ubuntu

[root@nfs docker]# docker push 8.130.33.145:8089/jd/ubuntu

Using default tag: latest

The push refers to repository [8.130.33.145:8089/jd/ubuntu]

202fe64c3ce3: Pushed

latest: digest: sha256:12149a2b7cca0a69237b84c5d7a52bb7f7db451518ace6f4190800c003642bd9 size: 529

7.6 查看自己的镜像仓库

成功上传镜像!!!

8. 测试,删除本机的镜像,去仓库里拉取

8.1 删除本机的镜像

执行:docker rmi 8.130.33.145:8089/jd/ubuntu

[root@nfs docker]# docker rmi 8.130.33.145:8089/jd/ubuntu

Untagged: 8.130.33.145:8089/jd/ubuntu:latest

Untagged: 8.130.33.145:8089/jd/ubuntu@sha256:12149a2b7cca0a69237b84c5d7a52bb7f7db451518ace6f4190800c003642bd9

[root@nfs docker]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

ubuntu latest 74f2314a03de 13 days ago 77.8MB

8.2 拉取自己仓库里的镜像(刚刚上传的ubuntu)

执行:docker pull 8.130.33.145:8089/jd/ubuntu

[root@nfs docker]# docker pull 8.130.33.145:8089/jd/ubuntu

Using default tag: latest

latest: Pulling from jd/ubuntu

Digest: sha256:12149a2b7cca0a69237b84c5d7a52bb7f7db451518ace6f4190800c003642bd9

Status: Downloaded newer image for 8.130.33.145:8089/jd/ubuntu:latest

8.130.33.145:8089/jd/ubuntu:latest

8.3 查看本机的镜像

[root@nfs docker]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

8.130.33.145:8089/jd/ubuntu latest 74f2314a03de 13 days ago 77.8MB

ubuntu latest 74f2314a03de 13 days ago 77.8MB

文章来源

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧