发布镜像到DockerHub仓库

1、去官网注册一个账号

2、通过命令行登录

  1. [root@centos01 ~]# docker login -u chenwenhao123
  2. Password:
  3. WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
  4. Configure a credential helper to remove this warning. See
  5. https://docs.docker.com/engine/reference/commandline/login/#credentials-store
  6. Login Succeeded

3、在发布之前要先给镜像重新打标签。标签的的名字要以登录名开头

[root@centos01 ~]# docker tag mytomcat01:8  chenwenhao123/mytomcat:8.0
[root@centos01 ~]# docker images
REPOSITORY               TAG       IMAGE ID       CREATED        SIZE
chenwenhao123/mytomcat   8.0       7b71dd962367   13 hours ago   576MB
mytomcat01               8         7b71dd962367   13 hours ago   576MB

4、发布

[root@centos01 ~]# docker push chenwenhao123/mytomcat:8.0
The push refers to repository [docker.io/chenwenhao123/mytomcat]
4f87d3000f1e: Pushed 
9a1efb1a7e88: Pushed 
6f8a269e441a: Pushed 
2653d992f4ef: Pushed 
8.0: digest: sha256:f494d83a1b75704eb8e40057b5482953168b43d63df1a537e2f284a561d1bd9b size: 1161

发布成功之后就能看到这个仓库了
image.png

5、可以通过 docker logout 命令退出登录

[root@centos01 ~]# docker logout
Removing login credentials for https://index.docker.io/v1/

发布镜像到阿里云镜像仓库

1、注册账号,创建一个镜像仓库(一个仓库对应一类镜像,里面可以放不同版本的镜像)
image.png
2、点击仓库,进去里面有操作指南
image.png
3、发布

# 登录仓库
[root@centos01 ~]# docker login --username=cwhnb123 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


# 修改 tag 信息
[root@centos01 ~]# docker tag 7b71dd962367 registry.cn-hangzhou.aliyuncs.com/chenwehao/mytomcat:8.0

[root@centos01 ~]# docker images
REPOSITORY                                             TAG       IMAGE ID       CREATED        SIZE
mytomcat01                                             8         7b71dd962367   14 hours ago   576MB
registry.cn-hangzhou.aliyuncs.com/chenwehao/mytomcat   8.0       7b71dd962367   14 hours ago   576MB

# 发布
[root@centos01 ~]# docker push registry.cn-hangzhou.aliyuncs.com/chenwehao/mytomcat:8.0
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/chenwehao/mytomcat]
4f87d3000f1e: Pushed 
9a1efb1a7e88: Pushed 
6f8a269e441a: Pushed 
2653d992f4ef: Pushed 
8.0: digest: sha256:f494d83a1b75704eb8e40057b5482953168b43d63df1a537e2f284a561d1bd9b size: 1161


# 退出登录
[root@centos01 ~]# docker logout
Removing login credentials for https://index.docker.io/v1/