docker镜像上传至Harbor及从Harbor下载

▶ 修改 docker daemon 使用 harbor

▷ 安装 harbor 的主机

在 harbor 的主机中配置。

添加 /etc/docker/daemon.json 文件,默认不存在,需要手动添加。

[root@server harbor]# vim /etc/docker/daemon.json

[root@server harbor]# cat /etc/docker/daemon.json
{
  "insecure-registries":["https://www.harborexample.com"]
}

重新加载 daemon 配置。

[root@server harbor]# systemctl daemon-reload
[root@server harbor]# systemctl restart docker

由于是重启 docker 所以 harbor 的9个容器可能会停止,这就需要使用 docker-compose 来使用。

[root@server harbor]# pwd
/home/harbor

[root@server harbor]# docker-compose down
[root@server harbor]# docker-compose up -d

▶ docker push

在其他的安装了docker的主机中,依旧需要在 /etc/docker/daemon.json 文件来配置。

[root@server ~]# vi /etc/docker/daemon.json

[root@server ~]# cat /etc/docker/daemon.json
{
   "insecure-registries":["https://www.harborexample.com"]
}

制作准备要 push 的镜像,给该镜像打 tag:

[root@server ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
nginx        latest    7f553e8bbc89   8 days ago   192MB

[root@server ~]# docker tag nginx:latest www.harborexample.com/library/ngnix:v1
[root@server ~]# docker images
REPOSITORY                            TAG       IMAGE ID       CREATED      SIZE
www.harborexample.com/library/ngnix   v1        7f553e8bbc89   8 days ago   192MB
nginx                                 latest    7f553e8bbc89   8 days ago   192MB

docker tag 镜像 寄存服务registry/仓库repository/镜像:tag


登陆 harbor:

[root@server ~]# docker login https://www.harborexample.com
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/#credential-stores

Login Succeeded

docker push 的具体操作:

[root@server ~]# docker push www.harborexample.com/library/ngnix:v1
The push refers to repository [www.harborexample.com/library/ngnix]
825fb68b6033: Pushed
7619c0ba3c92: Pushed
1c1f11fd65d6: Pushed
6b133b4de5e6: Pushed
3d07a4a7eb2a: Pushed
756474215d29: Pushed
8d853c8add5d: Pushed
v1: digest: sha256:719b34dba7bd01c795f94b3a6f3a5f1fe7d53bf09e79e355168a17d2e2949cef size: 1778

此时在浏览器中查看:


▶ docker pull

对于要对自己内部的harbor来使用 docker pull,在这之前需要对 /etc/hosts/etc/docker/daemon.json 做配置。

[root@server ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10 www.harborexample.com

[root@server ~]# cat /etc/docker/daemon.json
{
   "insecure-registries":["https://www.harborexample.com"]
}
[root@server ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

此时并没有镜像的存在。

指定 www.harborexample.com 的来拉取镜像。

[root@server ~]# docker pull www.harborexample.com/library/ngnix:v1
v1: Pulling from library/ngnix
302e3ee49805: Pull complete
d07412f52e9d: Pull complete
9ab66c386e9c: Pull complete
4b563e5e980a: Pull complete
55af3c8febf2: Pull complete
5b8e768fb22d: Pull complete
85177e2c6f39: Pull complete
Digest: sha256:719b34dba7bd01c795f94b3a6f3a5f1fe7d53bf09e79e355168a17d2e2949cef
Status: Downloaded newer image for www.harborexample.com/library/ngnix:v1
www.harborexample.com/library/ngnix:v1
[root@server ~]# docker images
REPOSITORY                            TAG       IMAGE ID       CREATED      SIZE
www.harborexample.com/library/ngnix   v1        7f553e8bbc89   8 days ago   192MB
posted @ 2024-10-11 20:48  takenika  阅读(287)  评论(0)    收藏  举报