Docker 基础 ( 十五 ) 发布自己的镜像

一、发布到 Docker Hub

  1. 地址 https://hub.docker.com/
  2. 确定这个账号可以登录
  3. 登录
[root@VM-0-6-centos ~]# 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
  • docker login -u 你的用户名 -p 你的密码
[root@VM-0-6-centos ~]# docker login -u yj
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        // 登录成功
  1. 提交自己的镜像
  • 会发现 push 不上去,因为如果没有前缀的话默认是 push 到 官方的library
[root@VM-0-6-centos ~]# docker push nginx
Using default tag: latest
The push refers to repository [docker.io/library/nginx]
075508cf8f04: Layer already exists 
5c865c78bc96: Layer already exists 
134e19b2fac5: Layer already exists 
83634f76e732: Layer already exists 
766fe2c3fc08: Layer already exists 
02c055ef67f5: Layer already exists 
errors:
denied: requested access to the resource is denied        // 提交失败
unauthorized: authentication required

解决方法:

  1. build的时候添加你的dockerhub用户名,然后在push就可以放到自己的仓库了
    docker build -t yj/mytomcat:0.1 .
[root@VM-0-6-centos ~]# docker build -t yj/mytomcat:0.1 .    // 构建镜像时创建带dockerhub 用户名的镜像
[root@VM-0-6-centos ~]# docker push yj/mytomcat:0.1    // 直接提交该镜像即可
  1. 使用docker tag 重新生成带dockerhub 用户名的镜像,然后再push
    docker tag 容器id yj/nginx-test:1.0
[root@VM-0-6-centos ~]# docker tag d1a364dc548d yj/nginx-test:1.0
[root@VM-0-6-centos ~]# docker push yj/nginx-test:1.0
[root@VM-0-6-centos ~]# docker push yj/nginx-test:1.0
The push refers to repository [docker.io/yj/nginx-test]
075508cf8f04: Mounted from library/nginx 
5c865c78bc96: Mounted from library/nginx 
134e19b2fac5: Mounted from library/nginx 
83634f76e732: Mounted from library/nginx 
766fe2c3fc08: Mounted from library/nginx 
02c055ef67f5: Mounted from library/mysql         // 提交成功
1.0: digest: sha256:61191087790c31e43eb37caa10de1135b002f10c09fdda7fa8a5989db74033aa size: 1570

二、发布到 阿里云镜像服务上

看官网 很详细https://cr.console.aliyun.com/repository

  1. 登录阿里云
  2. 找到容器镜像服务
  3. 创建命名空间
  4. 创建容器镜像
docker login --username=zchengx registry.cn-shenzhen.aliyuncs.com
docker tag [ImageId] registry.cn-shenzhen.aliyuncs.com/dsadxzc/cheng:[镜像版本号]
# 修改id 和 版本
docker tag a5ef1f32aaae registry.cn-shenzhen.aliyuncs.com/dsadxzc/cheng:1.0
# 修改版本
docker push registry.cn-shenzhen.aliyuncs.com/dsadxzc/cheng:[镜像版本号]
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容