发布自己的镜像
DockerHub
1、地址:https://hub.docker.com/注册自己的账号
2、确定这个账号可以登录
3、在这个服务器上提交自己的镜像
# centos7环境
root@localhost test]# docker login --help
Usage: docker login [OPTIONS] [SERVER]
Log in to a Docker registry.
If no server is specified, the default is defined by the daemon.
Options:
-p, --password string Password
--password-stdin Take the password from stdin
-u, --username string Username
# 登录账号
[root@localhost test]# docker login -u bruceliu1973
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
4、登录完毕,可以提交镜像,执行docker push命令
# 在centos7环境执行,但是出现一个问题
[root@localhost test]# docker push diytomcat
Using default tag: latest
The push refers to repository [docker.io/library/diytomcat]
41597dc9883c: Preparing
ba91795798ac: Preparing
43b27989aa87: Preparing
9445929b0a14: Preparing
74ddd0ec08fa: Preparing
denied: requested access to the resource is denied
# 解决push镜像的问题
# 给镜像增加一个tag
# 语法,[root@localhost test]#docker tag 容器id username/imagename *****username 是dockerhub用户名,imagename是镜像名, imagename一定跟要push的镜像名一样,否则还是被拒绝
[root@localhost test]# docker tag 66f61ab160f4 bruceliu1973/diytomcat:1.0
# 修改为username/imagename:tag格式,push成功,如下图
[root@localhost tomcat]# docker push bruceliu1973/diytomcat:1.0
The push refers to repository [docker.io/bruceliu1973/diytomcat]
41597dc9883c: Pushed
ba91795798ac: Pushed
43b27989aa87: Pushed
9445929b0a14: Pushed
74ddd0ec08fa: Pushed
1.0: digest: sha256:f37ddc8c0333224c1e5a98588469919bad63aa5632722977c56720718e6886f5 size: 1372
注意:提交的时候也是按照镜像的层级来进行提交的。
阿里云镜像服务
1、登录阿里云
2、找到容器镜像服务(https://cr.console.aliyun.com/cn-hangzhou/instances)
3、创建命名空间
4、创建容器镜像
5、浏览阿里云
点击仓库,看到里面有一些基本信息。
# 登录阿里云
[root@localhost ~]# docker login --username=bruce刘晓伟 registry.cn-hangzhou.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json. # 宿主机这里存储用户名和密码,json文件未加密
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
# 登录成功以后,执行
[root@localhost ~]# docker tag[ImageId] registry.cn-hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:[镜像版本号]
# 本例
[root@localhost ~]# docker tag[ImageId] registry.cn- hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:66f61ab160f4
# docker push,严格按照阿里云镜像推送命令格式执行,否则会被拒绝
[root@localhost ~]# docker push bruceliu1973/diytomcat:1.0 # 这个命令格式传DockerHub可以,传阿里云拒绝
# 按照阿里云格式推送到Registry,[镜像版本号]为上一步骤生成的版本号,此例为1.0,不是imageId
[root@localhost ~]# docker tag[ImageId] registry.cn-hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:[镜像版本号]
# 实际操作命令格式
[root@localhost ~]# docker push registry.cn-hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:1.0
总结:阿里云容器镜像参考并严格按照官方文档格式执行命令。
以后如果想让自己的网站被大家访问,就可以把网站镜像发到阿里云或者DockerHub,然后大家pull—run— OK
小结:
镜像打包成一个tar压缩包,可以发送压缩包给别人,涉及到两个命令
[root@localhost ~]# docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
-o, --output string Write to a file, instead of STDOUT