docker之本地仓库(registry)搭建
程序员文章站
2022-07-14 14:32:51
...
一.利用docker hub仓库中的registry镜像创建本地镜像仓库的容器
#docker pull registry(拉取镜像)
#docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry
-d:后台运行容器
-p:将容器的5000端口映射到主机的5000端口,5000端口是registry的服务端口
-v:将容器的/var/lib/registry目录映射到主机的/myregistry目录下,用于存放镜像数据
二.修改本地镜像的名称
镜像名称的完整格式应该为:**【registry-host】:【port】/【库名】/【镜像名】:【tag】**只有docker hub上的镜像可以省略 【registry-host】:【port】
所以需要将本地镜像名改为全称
docker tag docker.io/httpd:latest 10.254.254.223:5000/registry/httpd:v1
三.上传镜像
# docker push 10.254.254.223:5000/registry/httpd:v1
The push refers to a repository [10.254.254.223:5000/registry/httpd]
0c60f06bdadc: Pushed
7a0960d9b679: Pushed
8b16516271d6: Pushed
5bcb93651a74: Pushed
1c95c77433e8: Pushed
v1: digest: sha256:009d113bb7c47437fe0b0b3fc8b88273c7ce2ad0e7c796adf977afc11f523a21 size: 1367
四.下载镜像
docker pull 10.254.254.223:5000/registry/httpd:v1
可能会有报错:
Get https://10.254.254.223:5000/v1/_ping: http: server gave HTTP response to HTTPS client
解决方案:
在”/etc/docker/“目录下,创建”daemon.json“文件。在文件中写入:
{
"registry-mirrors": [
"https://2lqq34jg.mirror.aliyuncs.com",
"https://pee6w651.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com"
],
"dns": ["8.8.8.8","8.8.4.4"],
"insecure-registries":["主机IP:5000"]
}
然后重启docker
systemctl daemon-reload
systemctl restart docker
至此本地仓库的创建完成!!
上一篇: (第九章) Hive企业级调优之本地模式