上传镜像到仓库

在这里插入图片描述

上传镜像到公开仓库

1、给要上传的镜像打标签

# 从206节点上传镜像到仓库(201)magedu项目,查看206镜像
[root@k8s-node2 ~]# docker images
REPOSITORY                                                  TAG           IMAGE ID       CREATED         SIZE
registry                                                    latest        b2cb11db9d3d   2 weeks ago     26.2MB
centos7.9                                                   v4.0          f9fa966f3abe   3 weeks ago     211MB
centos7.9                                                   v3.0          9d181c779007   3 weeks ago     204MB
centos7.9                                                   v2.0          c06d6e414d47   3 weeks ago     204MB
centos7.9                                                   v1.0          a7501b2f31f1   3 weeks ago     204MB
registry.cn-hangzhou.aliyuncs.com/gxy_docker2021/centos     7.9.2009-v2   8652b9f0cb4c   10 months ago   204MB
registry.cn-hangzhou.aliyuncs.com/gxy_docker2021/gxy_test   v1.0          8652b9f0cb4c   10 months ago   204MB
guoxuyang6888/centos                                        7.9.2009-v1   8652b9f0cb4c   10 months ago   204MB
centos                                                      7.9.2009      8652b9f0cb4c   10 months ago   204MB

2、查看打标签命令
在这里插入图片描述
在这里插入图片描述

3、复制到终端进行修改

# 给镜像打标签,格式:docker tag SOURCE_IMAGE[:TAG] 192.168.31.201/magedu/REPOSITORY[:TAG] 前边是源镜像,后边是传到仓库后的镜像,可以重名了
[root@k8s-node2 ~]# docker tag centos7.9:v4.0 192.168.31.201/magedu/centos7.9:v4.0

4、上传镜像到公开仓库

# 格式:docker push 打好tar的镜像:版本号,注意,打好tar的镜像格式是:仓库地址/项目/要上传的镜像:版本号,这里上传的时候不需要在push后在加仓库地址和项目目录了,因为打好的tar的镜像中包含,直接docker push + 要上传的镜像:版本即可
[root@k8s-node2 ~]# docker push 192.168.31.201/magedu/192.168.31.201/magedu/centos7.9:v4.0
The push refers to repository [192.168.31.201/magedu/192.168.31.201/magedu/centos7.9]
An image does not exist locally with the tag: 192.168.31.201/magedu/192.168.31.201/magedu/centos7.9
[root@k8s-node2 ~]# 
[root@k8s-node2 ~]# 
[root@k8s-node2 ~]# docker push 192.168.31.201/magedu/centos7.9:v4.0
The push refers to repository [192.168.31.201/magedu/centos7.9]
c5fb9f0f3efb: Pushed 
c406384a2b40: Pushed 
174f56854903: Pushed 
v4.0: digest: sha256:2aae8a55a7ee6e82fa88aa770964b49c624dce481362bf2fe89bc8159665174d size: 951

5、查看上传的镜像
在这里插入图片描述
在这里插入图片描述

6、下载镜像

从另外一台机器(205)下载206节点上传的镜像

# 登录205节点,查看当前镜像,确保不含206上传的镜像
[root@k8s-node1 ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
nginx                             latest    ad4c705f24d3   7 days ago    133MB
[root@k8s-node1 ~]# 

7、查看镜像拉取命令
在这里插入图片描述

# 登录205节点进行拉取
[root@k8s-node1 ~]# docker pull 192.168.31.201/magedu/centos7.9@sha256:2aae8a55a7ee6e82fa88aa770964b49c624dce481362bf2fe89bc8159665174d
Error response from daemon: Get "https://192.168.31.201/v2/": dial tcp 192.168.31.201:443: connect: connection refused

8、排错:此时我们发现请求被拒了,因为docker harbor默认是https请求,我们创建的时候走的是http,我们需要修改205节点的/lib/systemd/system/docker.service

# 修改第13行,在后边添加仓库的地址:--insecure-registry 192.168.31.201 --insecure-registry 192.168.31.204
[root@k8s-node1 ~]# vim /lib/systemd/system/docker.service
...
11 # exists and systemd currently does not support the cgroup feature set required
 12 # for containers run by docker
 13 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 192.168.31.201 --insecure-registry 192.168.31.204
 14 ExecReload=/bin/kill -s HUP $MAINPID
 ...

9、重启docker

[root@k8s-node1 ~]# systemctl daemon-reload
[root@k8s-node1 ~]# systemctl restart docker

10、重新拉取

# 拉取成功
[root@k8s-node1 ~]# docker pull 192.168.31.201/magedu/centos7.9@sha256:2aae8a55a7ee6e82fa88aa770964b49c624dce481362bf2fe89bc8159665174d
192.168.31.201/magedu/centos7.9@sha256:2aae8a55a7ee6e82fa88aa770964b49c624dce481362bf2fe89bc8159665174d: Pulling from magedu/centos7.9
2d473b07cdd5: Pull complete 
017960a6d76e: Pull complete 
8ee6fdd9e641: Pull complete 
Digest: sha256:2aae8a55a7ee6e82fa88aa770964b49c624dce481362bf2fe89bc8159665174d
Status: Downloaded newer image for 192.168.31.201/magedu/centos7.9@sha256:2aae8a55a7ee6e82fa88aa770964b49c624dce481362bf2fe89bc8159665174d
192.168.31.201/magedu/centos7.9@sha256:2aae8a55a7ee6e82fa88aa770964b49c624dce481362bf2fe89bc8159665174d

11、查看下载后的镜像

[root@k8s-node1 ~]# docker images
REPOSITORY                        TAG       IMAGE ID       CREATED       SIZE
192.168.31.201/magedu/centos7.9   <none>    f9fa966f3abe   3 weeks ago   211MB
nginx                             latest    ad4c705f24d3   7 days ago    133MB

上传镜像到私有仓库

打标签

# 本次从205上传镜像到私有仓库test
[root@k8s-node1 ~]# docker tag nginx:latest 192.168.31.201/test/nginx:v1.0

查看打过标签的镜像

[root@k8s-node1 ~]# docker images
REPOSITORY                        TAG       IMAGE ID       CREATED       SIZE
192.168.31.201/test/nginx         v1.0      ad4c705f24d3   7 days ago    133MB
nginx                             latest    ad4c705f24d3   7 days ago    133MB
192.168.31.201/magedu/centos7.9   <none>    f9fa966f3abe   3 weeks ago   211MB

上传镜像到私有仓库test

[root@k8s-node1 ~]# docker push 192.168.31.201/test/nginx:v1.0
The push refers to repository [192.168.31.201/test/nginx]
fac15b2caa0c: Preparing 
f8bf5746ac5a: Preparing 
d11eedadbd34: Preparing 
797e583d8c50: Preparing 
bf9ce92e8516: Preparing 
d000633a5681: Waiting 
unauthorized: unauthorized to access repository: test/nginx, action: push: unauthorized to access repository: test/nginx, action: push

排错:上传镜像是提示未认证的用户,需要认证后才能上传

查看镜像是否上传成功
在这里插入图片描述
发现没有上传成功

解决办法:

登录仓库

# 登录仓库,用户admin 密码123456
[root@k8s-node1 ~]# docker login 192.168.31.201
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@k8s-node1 ~]# docker push 192.168.31.201/test/nginx:v1.0
The push refers to repository [192.168.31.201/test/nginx]
fac15b2caa0c: Pushed 
f8bf5746ac5a: Pushed 
d11eedadbd34: Pushed 
797e583d8c50: Pushed 
bf9ce92e8516: Pushed 
d000633a5681: Pushed 
v1.0: digest: sha256:6fe11397c34b973f3c957f0da22b09b7f11a4802e1db47aef54c29e2813cc125 size: 1570

查看上传后的镜像
在这里插入图片描述
在这里插入图片描述
上传成功!

下载镜像

# 从206上下载镜像
[root@k8s-node2 ~]# docker pull 192.168.31.201/test/nginx@sha256:6fe11397c34b973f3c957f0da22b09b7f11a4802e1db47aef54c29e2813cc125
192.168.31.201/test/nginx@sha256:6fe11397c34b973f3c957f0da22b09b7f11a4802e1db47aef54c29e2813cc125: Pulling from test/nginx
a330b6cecb98: Pull complete 
e0ad2c0621bc: Pull complete 
9e56c3e0e6b7: Pull complete 
09f31c94adc6: Pull complete 
32b26e9cdb83: Pull complete 
20ab512bbb07: Pull complete 
Digest: sha256:6fe11397c34b973f3c957f0da22b09b7f11a4802e1db47aef54c29e2813cc125
Status: Downloaded newer image for 192.168.31.201/test/nginx@sha256:6fe11397c34b973f3c957f0da22b09b7f11a4802e1db47aef54c29e2813cc125
192.168.31.201/test/nginx@sha256:6fe11397c34b973f3c957f0da22b09b7f11a4802e1db47aef54c29e2813cc125

查看镜像

[root@k8s-node2 ~]# docker images
REPOSITORY                                                  TAG           IMAGE ID       CREATED         SIZE
192.168.31.201/test/nginx                                   <none>        ad4c705f24d3   7 days ago      133MB
registry                                                    latest        b2cb11db9d3d   2 weeks ago     26.2MB
centos7.9                                                   v4.0          f9fa966f3abe   3 weeks ago     211MB
192.168.31.201/magedu/centos7.9                             v4.0          f9fa966f3abe   3 weeks ago     211MB
centos7.9                                                   v3.0          9d181c779007   3 weeks ago     204MB
centos7.9                                                   v2.0          c06d6e414d47   3 weeks ago     204MB
centos7.9                                                   v1.0          a7501b2f31f1   3 weeks ago     204MB
guoxuyang6888/centos                                        7.9.2009-v1   8652b9f0cb4c   10 months ago   204MB
centos                                                      7.9.2009      8652b9f0cb4c   10 months ago   204MB
registry.cn-hangzhou.aliyuncs.com/gxy_docker2021/centos     7.9.2009-v2   8652b9f0cb4c   10 months ago   204MB
registry.cn-hangzhou.aliyuncs.com/gxy_docker2021/gxy_test   v1.0          8652b9f0cb4c   10 months ago   204MB

下载成功!

注意: 由于206已经登录过镜像仓库了,并且在家目录下的 .docker目录中生成了config.json文件,所有下次登录仓库无需账号密码,所以从私有仓库下载也无需登录了。

[root@k8s-node2 ~]# cat .docker/config.json 
{
        "auths": {
                "192.168.31.201": {
                        "auth": "YWRtaW46MTIzNDU2"
                },
                "https://index.docker.io/v1/": {
                        "auth": "Z3VveHV5YW5nNjg4ODpndW94dXlhbmcxOTkx"
                },
                "registry.cn-hangzhou.aliyuncs.com": {
                        "auth": "Z3VveHV5YW5nMTk5MToxcWF6IVFBWg=="
                }
        }
}[root@k8s-node2 ~]# pwd
/root

auth": “Z3VveHV5YW5nNjg4ODpndW94dXlhbmcxOTkx”
},
“registry.cn-hangzhou.aliyuncs.com”: {
“auth”: “Z3VveHV5YW5nMTk5MToxcWF6IVFBWg==”
}
}
}[root@k8s-node2 ~]# pwd
/root


  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值