拉取上传镜像
拉取镜像
docker pull <registry>[:<port>]/[<namespace>/]<name>:<tag>
# registry :仓库服务器地址;不指定默认是docker hub
# port :端口;默认443,因为是https协议;
# namespace :名称空间,指是哪个用户的仓库,如果是顶层仓库,可以省;
# name :仓库名;
# tag :标签名;默认是latest版本;
上传镜像
docker push [OPTION]NAME[:TAG]
搭建私有仓库distribution
docker 提供的开源registry,只能作为存储镜像的仓库,没有额外的功能(比如管理页面等);
# 拉取镜像
[[email protected] ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
486039affc0a: Pull complete
ba51a3b098e6: Pull complete
8bb4c43d6c8e: Pull complete
6f5f453e5f2d: Pull complete
42bc10b72f42: Pull complete
Digest: sha256:7d081088e4bfd632a88e3f3bcd9e007ef44a796fddfe3261407a3f9f04abe1e7
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
# 启动registry容器
[[email protected] ~]# docker run -d --name registry -p 5000:5000 -v /data/registry:/var/lib/registry registry:latest
2edaee8264d9276e88fa776ec73bcd2fe8810e340fba43def88036751f3a3dc1
从私有仓库上传下载镜像
# 给本地仓库打上合适的标签
[[email protected] ~]# docker tag busybox:latest 192.168.100.61:5000/busybox:v0.1
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.100.61:5000/busybox v0.1 83aa35aa1c79 5 days ago 1.22MB
# 上传镜像(失败原因:docker上传下载默认只支持https协议,搭建的私有仓库是http协议
[[email protected] ~]# docker push 192.168.100.61:5000/busybox:v0.1
The push refers to repository [192.168.100.61:5000/busybox]
Get https://192.168.100.61:5000/v2/: http: server gave HTTP response to HTTPS client
# 将私有仓库认证为安全仓库,重启
[[email protected] ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"], # 这个是我的阿里云镜像加速器地址
"insecure-registries": ["192.168.100.61:5000"]
}
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl restart docker
# 再次上传镜像
[[email protected] ~]# docker push 192.168.100.61:5000/busybox:v0.1
The push refers to repository [192.168.100.61:5000/busybox]
a6d503001157: Pushed
v0.1: digest: sha256:afe605d272837ce1732f390966166c2afff5391208ddd57de10942748694049d size: 527
# 在私有仓库验证
[[email protected] ~]# ls /data/registry/docker/registry/v2/
blobs repositories
# 删除镜像再从私有仓库拉取
[[email protected] ~]# docker rmi 192.168.100.61:5000/busybox:v0.1
Untagged: 192.168.100.61:5000/busybox:v0.1
Untagged: 192.168.100.61:5000/[email protected]:afe605d272837ce1732f390966166c2afff5391208ddd57de10942748694049d
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 83aa35aa1c79 5 days ago 1.22MB
registry latest 708bc6af7e5e 7 weeks ago 25.8MB
[[email protected] ~]# docker pull 192.168.100.61:5000/busybox:v0.1
v0.1: Pulling from busybox
Digest: sha256:afe605d272837ce1732f390966166c2afff5391208ddd57de10942748694049d
Status: Downloaded newer image for 192.168.100.61:5000/busybox:v0.1
192.168.100.61:5000/busybox:v0.1
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.100.61:5000/busybox v0.1 83aa35aa1c79 5 days ago 1.22MB
busybox latest 83aa35aa1c79 5 days ago 1.22MB
registry latest 708bc6af7e5e 7 weeks ago 25.8MB
原文地址:https://www.cnblogs.com/HsLM/p/12496889.html
时间: 2024-10-16 04:08:40