1、DockerHub
地址:Docker Hub 需要注册。
在我们的服务器上提交自己的镜像。
测试
# 查看登录命令
[root@localhost home]$ 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 home]$ docker login -u mianbaozzz
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@localhost home]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my_tomcat 1.0 18c352ccb430 23 hours ago 821MB
# 提交报错,首先使用 docker tag 命令给本地镜像起标签
[root@localhost home]$ docker push mianbao/my_tomcat:1.0
The push refers to repository [docker.io/mianbao/my_tomcat]
An image does not exist locally with the tag: mianbao/my_tomcat
# 创建一个引用 SOURCE_IMAGE 的标记 TARGET_IMAGE
[root@localhost home]$ docker tag --help
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
# docker tag [镜像名|镜像ID] hub-user/repo-name [:tag]
# 给本地镜像起 tag
[root@localhost home]$ docker tag 18c352ccb430 mianbao/my_tomcat:1.0
[root@localhost home]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my_tomcat 1.0 18c352ccb430 23 hours ago 821MB
mianbao/my_tomcat 1.0 18c352ccb430 23 hours ago 821MB
# 再次提交
[root@localhost home]$ docker push mianbao/my_tomcat:1.0
The push refers to repository [docker.io/mianbao/my_tomcat]
eda11d1334ce: Preparing
4ecf1c216317: Preparing
43c96235a830: Preparing
d8525728b109: Preparing
174f56854903: Preparing
# denied:请求的资源访问被拒绝
denied: requested access to the resource is denied
# 镜像名称要改为 ==> 注册用户名/镜像名 <== 形式,否则被拒绝。
[root@localhost home]$ docker tag 18c352ccb430 mianbaozzz/my_tomcat:1.0
[root@localhost home]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my_tomcat 1.0 18c352ccb430 23 hours ago 821MB
mianbao/my_tomcat 1.0 18c352ccb430 23 hours ago 821MB
mianbaozzz/my_tomcat 1.0 18c352ccb430 23 hours ago 821MB
[root@localhost home]$ docker push mianbaozzz/my_tomcat:1.0
The push refers to repository [docker.io/mianbaozzz/my_tomcat]
eda11d1334ce: Pushing [===========> ] 52.54MB/231.7MB
4ecf1c216317: Pushed
43c96235a830: Pushing [> ] 4.979MB/369.1MB
d8525728b109: Pushing 2.56kB
174f56854903: Preparing
# ----------成功后---------------
1.0: digest: sha256:3aae408e58cb83c63d1e9869d9e0e332faa865b0b28c39f9b30a594b3a1ca9ac size: 1373
2、阿里云镜像服务
2.1、登录阿里云
2.2、搜索容器镜像服务,点击进入控制台
地址:容器镜像服务 ACR
2.3、创建个人实例
2.4、新手指引
2.5、创建命名空间
2.6、创建镜像仓库
2.7、操作指南
1. 登录阿里云Docker Registry
$ docker login --username=aliyun5682911351 registry.cn-hangzhou.aliyuncs.com
用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。您可以在访问凭证页面修改凭证密码。
2. 从Registry中拉取镜像
$ docker pull registry.cn-hangzhou.aliyuncs.com/mianbao/mianbao-test:[镜像版本号]
3. 将镜像推送到Registry
$ docker login --username=aliyun5682911351 registry.cn-hangzhou.aliyuncs.com
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/mianbao/mianbao-test:[镜像版本号]
$ docker push registry.cn-hangzhou.aliyuncs.com/mianbao/mianbao-test:[镜像版本号]
4. 选择合适的镜像仓库地址
从 ECS 推送镜像时,可以选择使用镜像仓库内网地址。推送速度将得到提升并且将不会损耗您的公网流量。
如果您使用的机器位于 VPC 网络,请使用 registry-vpc.cn-hangzhou.aliyuncs.com 作为 Registry 的域名登录。
2.8、测试
测试
# 登录
[root@localhost home]$ docker login --username=aliyun5682911351 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@localhost home]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my_tomcat 1.0 18c352ccb430 24 hours ago 821MB
[root@localhost home]$ docker tag 18c352ccb430 registry.cn-hangzhou.aliyuncs.com/mianbao/mianbao-test:1.0
[root@localhost home]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my_tomcat 1.0 18c352ccb430 24 hours ago 821MB
registry.cn-hangzhou.aliyuncs.com/mianbao/mianbao-test 1.0 18c352ccb430 24 hours ago 821MB
# 推送
[root@localhost home]$ docker push registry.cn-hangzhou.aliyuncs.com/mianbao/mianbao-test:1.0
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/mianbao/mianbao-test]
eda11d1334ce: Pushed
4ecf1c216317: Pushed
43c96235a830: Pushed
d8525728b109: Pushed
174f56854903: Pushed
1.0: digest: sha256:3aae408e58cb83c63d1e9869d9e0e332faa865b0b28c39f9b30a594b3a1ca9ac size: 1373