Docker学习(四) -- 制作私有镜像推送到阿里云或私服
1. 将自己创建的镜像发布到阿里云仓库:1.1 在阿里云容器镜像服务中创建个人实例1.2 进入个人实例,创建命名空间1.3 创建镜像仓库,会产生一些阿里云为你生成的命令操作指南:1. 登录阿里云Docker Registry$ docker login --username=messi9**** registry.cn-hangzhou.aliyuncs.com用于登录的用户名为阿里云账号全名,密
·
1. 将自己创建的镜像发布到阿里云仓库:
1.1 在阿里云容器镜像服务中创建个人实例
1.2 进入个人实例,创建命名空间
1.3 创建镜像仓库,会产生一些阿里云为你生成的命令
操作指南:
1. 登录阿里云Docker Registry
$ docker login --username=messi9**** registry.cn-hangzhou.aliyuncs.com
用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。
您可以在访问凭证页面修改凭证密码。
2. 从Registry中拉取镜像
$ docker pull registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94:[镜像版本号]
3. 将镜像推送到Registry
$ docker login --username=messi9**** registry.cn-hangzhou.aliyuncs.com
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94:[镜像版本号]
$ docker push registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94:[镜像版本号]
请根据实际镜像信息替换示例中的[ImageId]和[镜像版本号]参数。
4. 选择合适的镜像仓库地址
从ECS推送镜像时,可以选择使用镜像仓库内网地址。推送速度将得到提升并且将不会损耗您的公网流量。
如果您使用的机器位于VPC网络,请使用 registry-vpc.cn-hangzhou.aliyuncs.com 作为Registry的域名登录。
5. 示例
使用"docker tag"命令重命名镜像,并将它通过专有网络地址推送至Registry。
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry.aliyuncs.com/acs/agent 0.7-dfb6816 37bb9c63c8b2 7 days ago 37.89 MB
$ docker tag 37bb9c63c8b2 registry-vpc.cn-hangzhou.aliyuncs.com/acs/agent:0.7-dfb6816
使用 "docker push" 命令将该镜像推送至远程。
$ docker push registry-vpc.cn-hangzhou.aliyuncs.com/acs/agent:0.7-dfb6816
1.4 将之前commit的包含vim命令的ubuntu推送到阿里云镜像及从阿里云拉取:
在push的过程中,可以看到,我们push的with-vim镜像分为了2个文件:9a91045e4b63和9f54eef41275,而9f54eef41275文件大小是72.8MB,就是原来的ubuntu的镜像,更加证明了,镜像是基于分层文件系统的。
[root@yhx ~]# docker login --username=messi94yhx 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@yhx ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
with-vim/with-vim 1.0 9b6363fb0c60 22 minutes ago 175MB
a/a latest c4b611df9300 2 hours ago 109MB
tomcat latest fb5657adc892 2 months ago 680MB
redis latest 7614ae9453d1 2 months ago 113MB
ubuntu latest ba6acccedd29 5 months ago 72.8MB
hello-world latest feb5d9fea6a5 5 months ago 13.3kB
[root@yhx ~]# docker tag 9b6363fb0c60 registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94:1.0
[root@yhx ~]# docker push registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94:1.0
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94]
9a91045e4b63: Pushed
9f54eef41275: Pushed
1.0: digest: sha256:6ab5e018896a24c1673c9a365ba0c2909c67d789993e905fbb971289b500dc71 size: 741
[root@yhx ~]#
拉取不多演示
2. 将镜像上传到私服
2.1 下载docker registry
[root@yhx ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete
0d96da54f60b: Pull complete
5b27040df4a2: Pull complete
e2ead8259a04: Pull complete
3790aef225b9: Pull complete
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@yhx ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
with-vim/with-vim 1.0 9b6363fb0c60 36 minutes ago 175MB
registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94 1.0 9b6363fb0c60 36 minutes ago 175MB
a/a latest c4b611df9300 2 hours ago 109MB
tomcat latest fb5657adc892 2 months ago 680MB
redis latest 7614ae9453d1 2 months ago 113MB
registry latest b8604a3fe854 4 months ago 26.2MB
ubuntu latest ba6acccedd29 5 months ago 72.8MB
hello-world latest feb5d9fea6a5 5 months ago 13.3kB
[root@yhx ~]#
2.2 运行私有库,相当于本地有一个docker hub
默认情况,仓库被创建在容器的/var/lib/registry目录下,建议自行用容器卷映射,方便于宿主机联调
[root@yhx ~]# docker run -d -p 5000:5000 -v /zzyyuser/myregistry:/tmp/registry --privileged=true registry
c5953d191749db444c8bcb4f7b6335bd4fae6565e5a649d1be2f41f16c722aac
[root@yhx ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5953d191749 reg istry "/entrypoint.sh /etc…" 12 seconds ago Up 11 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp naughty_napier
2.3 查看私服是否上传过镜像:
[root@yhx ~]# curl -GET http://**.**.**.**:5000/v2/_catalog
{"repositories":[]}
2.4 修改镜像为符合规范的tag:
docker tag 镜像名:tag Host:Port/Repository:tag
[root@yhx ~]# docker tag with-vim/with-vim:1.0 **.**.**.**:5000/with-vim:1.0
[root@yhx ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
**.**.**.**:5000/with-vim 1.0 9b6363fb0c60 48 minutes ago 175MB
with-vim/with-vim 1.0 9b6363fb0c60 48 minutes ago 175MB
registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94 1.0 9b6363fb0c60 48 minutes ago 175MB
a/a latest c4b611df9300 2 hours ago 109MB
tomcat latest fb5657adc892 2 months ago 680MB
redis latest 7614ae9453d1 2 months ago 113MB
registry latest b8604a3fe854 4 months ago 26.2MB
ubuntu latest ba6acccedd29 5 months ago 72.8MB
hello-world latest feb5d9fea6a5 5 months ago 13.3kB
[root@yhx ~]#
2.5 修改配置文件使之支持http
cd /etc/docker/daemon.json
添加:“insecure-registries”:[172.16.162.115:5000],注意加逗号
{
"registry-mirrors": ["https://jdhg9s8z.mirror.aliyuncs.com"],
"insecure-registries":[内网ip:5000]
}
2.6 推送镜像到私服
[root@yhx docker]# docker push 内网id:5000/with-vim:1.0
The push refers to repository [内网id:5000/with-vim]
9a91045e4b63: Pushed
9f54eef41275: Pushed
1.0: digest: sha256:6ab5e018896a24c1673c9a365ba0c2909c67d789993e905fbb971289b500dc71 size: 741
[root@yhx docker]#
2.7 验证
[root@yhx docker]# curl -GET http://内网id:5000/v2/_catalog
{"repositories":["with-vim"]}
[root@yhx docker]#
2.8 删除本地镜像并从私服拉取
删除本地镜像,不多展示
拉取:
[root@yhx docker]# docker pull 内网id:5000/with-vim:1.0
1.0: Pulling from with-vim
Digest: sha256:6ab5e018896a24c1673c9a365ba0c2909c67d789993e905fbb971289b500dc71
Status: Downloaded newer image for 内网id:5000/with-vim:1.0
内网id:5000/with-vim:1.0
[root@yhx docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
内网id:5000/with-vim 1.0 9b6363fb0c60 2 hours ago 175MB
with-vim/with-vim 1.0 9b6363fb0c60 2 hours ago 175MB
registry.cn-hangzhou.aliyuncs.com/yhx94/yhx94 1.0 9b6363fb0c60 2 hours ago 175MB
a/a latest c4b611df9300 3 hours ago 109MB
tomcat latest fb5657adc892 2 months ago 680MB
redis latest 7614ae9453d1 2 months ago 113MB
registry latest b8604a3fe854 4 months ago 26.2MB
ubuntu latest ba6acccedd29 5 months ago 72.8MB
hello-world latest feb5d9fea6a5 5 months ago 13.3kB
[root@yhx docker]#
更多推荐
已为社区贡献1条内容
所有评论(0)