镜像提交dockerhub(还没测,待完善文档)

1、注册dockerhub

访问https://hub.docker.com注册账号。

2、确定账号可以使用

#在服务器直接使用login,输入密码登录
[root@k8s-master ~]# docker login -u 15238368265
Password: 

3、在服务器提交自己的镜像

#如果你的镜像没有版本号
[root@k8s-master ~]# docker images
dockertomcat0.3                                            latest    6073bd77b6ae   18 hours ago    591MB
#必须设置版本号
docker tag 6073bd77b6ae centos_tomcat:1.0

#提交镜像,格式如下:
docker push 作者名/容器:版本号
例如:
docker push hcf/centos_tomcat:1.0

镜像提交阿里云

1、登录阿里云官网新增命名空间

阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台

新增命名空间,不开会员只能3个命名空间,1个命名空间里可以上传多个镜像

新增镜像仓库(随便新增一个,新增好后,点仓库名称可以看到服务器怎么登录、提交、下载镜像)

点击仓库名称,即可看到如何登录,如何提交,如何下载镜像

2、使用服务器登录阿里云,上传镜像

#登录阿里云
[root@k8s-master ~]# docker login -u 1523836xxxx registry.cn-hangzhou.aliyuncs.com
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-master ~]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED         SIZE
dockertomcat                                               1.0       6073bd77b6ae   18 hours ago    591MB

#提交该镜像到阿里云(这里一直要做tag,把镜像名字改为registry……,阿里云上要求的)
docker tag 6073bd77b6ae registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat:2.0

#修改完成后,push提交阿里云
docker push registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat:2.0
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat]
631c51d58934: Pushed 
0bfb234a6b19: Pushed 
74ddd0ec08fa: Pushed 
2.0: digest: sha256:4108b5ef6e5ee4bdfd8a66fcc951bbf02bc86f3586ea5e3109fcc1d6c04fd288 size: 954
#出现上面内容,提交成功


提交成功,查看阿里云

#下载刚才提交的镜像,拉取前名字、版本本地不能有重复的
#查看本地有哪些
[root@k8s-master ~]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
dockertomcat0.1       latest    f574341b0e41   19 hours ago    591MB
dockertomcat0.2       latest    4292fad46f8d   19 hours ago    591MB

#拉取一个不存在的版本3.0,提示错误
[root@k8s-master ~]# docker pull registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat:3.0
Error response from daemon: manifest for registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat:3.0 not found: manifest unknown: manifest unknown

#拉取真是存在的版本2.0 
[root@k8s-master ~]# docker pull registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat:2.0
2.0: Pulling from xuexiban/dockertomcat
Digest: sha256:4108b5ef6e5ee4bdfd8a66fcc951bbf02bc86f3586ea5e3109fcc1d6c04fd288
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat:2.0
registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat:2.0

# 拉取成功,进行查看
[root@k8s-master ~]# docker images
REPOSITORY                                                TAG       IMAGE ID       CREATED         SIZE
dockertomcat0.1                                           latest    f574341b0e41   19 hours ago    591MB
dockertomcat0.2                                           latest    4292fad46f8d   19 hours ago    591MB
registry.cn-hangzhou.aliyuncs.com/xuexiban/dockertomcat   2.0       6073bd77b6ae   19 hours ago    591MB


镜像save为jar包和load为jar

save:把镜像打为压缩包

#使用save把镜像打为jar包
#-o dockertomcat.jar:指定输出到的文件到dockertomcat.jar
#支持jar、.tar 、 .tar.gz等格式
[root@k8s-master ~]# docker save -o dockertomcat.jar dockertomcat:1.0
#打包好后,进行查看,有个jar文件
[root@k8s-master ~]# ll
-rw-------. 1 root root 599158784 5月  24 10:44 dockertomcat.jar

#对多个镜像进行打包
[root@k8s-master ~]# docker save -o duojingxiang.jar dockertomcat0.1:latest hello-world:latest mysql:5.7 
[root@k8s-master ~]# ls
dockertomcat.jar  duojingxiang.jar

load:把压缩包里的镜像拉取出来 

#查看本地没有文件
[root@k8s-node1 docker]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

#拉取
[root@k8s-node1 docker]# docker load -i duojingxiang.jar 
74ddd0ec08fa: Loading layer [==================================================>]  238.6MB/238.6MB
0bfb234a6b19: Loading layer [==================================================>]  16.84MB/16.84MB
631c51d58934: Loading layer [==================================================>]  343.7MB/343.7MB
Loaded image: dockertomcat0.1:latest
63a41026379f: Loading layer [==================================================>]  11.78kB/11.78kB
Loaded image: hello-world:latest
cff044e18624: Loading layer [==================================================>]    145MB/145MB
7ff7abf4911b: Loading layer [==================================================>]  11.26kB/11.26kB
8b2952eb02aa: Loading layer [==================================================>]  2.383MB/2.383MB
d76a5f910f6b: Loading layer [==================================================>]  13.91MB/13.91MB
8527ccd6bd85: Loading layer [==================================================>]  7.168kB/7.168kB
4555572a6bb2: Loading layer [==================================================>]  3.072kB/3.072kB
0d9e9a9ce9e4: Loading layer [==================================================>]  79.38MB/79.38MB
532b66f4569d: Loading layer [==================================================>]  3.072kB/3.072kB
337ec6bae222: Loading layer [==================================================>]  278.8MB/278.8MB
73cb62467b8f: Loading layer [==================================================>]  17.41kB/17.41kB
441e16cac4fe: Loading layer [==================================================>]  1.536kB/1.536kB
Loaded image: mysql:5.7
[root@k8s-node1 docker]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED         SIZE
dockertomcat0.1   latest    f574341b0e41   37 hours ago    591MB
hello-world       latest    74cc54e27dc4   4 months ago    10.1kB
mysql             5.7       5107333e08a8   17 months ago   501MB

#启动一个镜像查看是可以正常run的

[root@k8s-node1 docker]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐