一、发布到 Docker Hub
- 地址 https://hub.docker.com/
- 确定这个账号可以登录
- 登录
[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 // 登录成功
- 提交自己的镜像
- 会发现
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
解决方法:
-
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 // 直接提交该镜像即可
- 使用
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
- 登录阿里云
- 找到容器镜像服务
- 创建命名空间
- 创建容器镜像
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:[镜像版本号]