DOCKER本地仓库
概述
随着docker的应用越来越多,安装部署越来越方便,批量自动化的镜像生成和发布都需要docker仓库的本地化应用。
试用了docker的本地仓库功能,简单易上手,记录下来以备后用。
环境
centos:CentOS release 7.0 (Final)或以上版本
Docker version 24.0.6, build ed223bc
下载registry镜像
从官方下载registry镜像和debian镜像。
sudo docker pull registry
sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 0ae1560ca86f 8 days ago 25.4MB
debian bullseye 909f4919a453 3 weeks ago 124MB
启动registry容器
使用默认5000端口映射registry容器。
sudo docker run -d -p 5000:5000 --restart=always --name registry registry:latest
查看启动情况。
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3795a6fcd7e7 registry:latest "/entrypoint.sh /etc…" 4 hours ago Up 4 hours 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp registry
打开registry的web页面,注意要用http不带s。
http://10.55.55.136:5000/v2/_catalog
{"repositories":["test/debian"]}
docker客户端配置
修改docker客户端配置,没有则创建。
sudo vi /etc/docker/daemon.json
{
"insecure-registries":[
"10.55.55.136:5000",
"localhost:5000"
]
}
重启docker。
sudo systemctl restart docker
上传镜像到registry
查看当前镜像,有debian的bulleye版本。
sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 0ae1560ca86f 8 days ago 25.4MB
debian bullseye 909f4919a453 3 weeks ago 124MB
对debian:bullseye打tag。
sudo docker tag debian:bullseye 10.55.55.136:5000/test/debian:v1.0
sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 0ae1560ca86f 9 days ago 25.4MB
10.55.55.136:5000/test/debian v1.0 909f4919a453 3 weeks ago 124MB
debian bullseye 909f4919a453 3 weeks ago 124MB
上传自定义镜像。
sudo docker push 10.55.55.136:5000/test/debian:v1.0
push时如果产生下面的报错,返回上一步,修改docker客户端配置解决。
The push refers to repository [10.55.55.136:5000/test/debian]
Get "https://10.55.55.136:5000/v2/": http: server gave HTTP response to HTTPS client
下载自定义镜像
首先删除本地自定义镜像,然后从registry重新下载。
sudo docker rmi 10.55.55.136:5000/test/debian:v1.0
sudo docker pull 10.55.55.136:5000/test/debian:v1.0
sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 0ae1560ca86f 8 days ago 25.4MB
10.55.55.136:5000/test/debian v1.0 909f4919a453 3 weeks ago 124MB
debian bullseye 909f4919a453 3 weeks ago 124MB
总结
Docker镜像的本地库是CI自动化流程的必要步骤。
Docker的registry镜像简单易上手。
空空如常
求真得真