docker搭建私有仓库
运行 registry 镜像
安装 Docker 后,可以通过官方提供的 registry 镜像来简单搭建一套本地私有仓库环境:
查看官方文档:https://hub.docker.com/_/registry
注意:当前机器是centos7, ip 是 192.168.245.133
$ docker run -d -p 5000:5000 --restart always --name registry registry:2
创建私有镜像
$ docker pull ubuntu
$ docker tag ubuntu localhost:5000/ubuntu
# 本机ip是192.168.245.133。为什么不用ip,后面会说
$ docker push localhost:5000/ubuntu
查看镜像
$ docker images
localhost:5000/ubuntu latest ba6acccedd29 11 months ago 72.8MB
查看镜像仓库中的镜像
# 列出所有镜像
$ curl http://localhost:5000/v2/_catalog
{"repositories":["ubuntu"]}
# 列出镜像的所有标签
$ curl http://localhost:5000/v2/ubuntu/tags/list
{"name":"ubuntu","tags":["latest"]}
此时我们可以在另外一台机器(192.168.124.132)来拉去下这个镜像
[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu
Using default tag: latest
Error response from daemon: Get "https://192.168.245.133:5000/v2/": http: server gave HTTP response to HTTPS client
遇到上面错误,我们需要修改下 /etc/docker/daemon.json配置
{
"insecure-registries":["192.168.245.133:5000"],
"registry-mirrors": ["https://9fgss2yh.mirror.aliyuncs.com"]
}
配置 insecure-registries(不安全的注册地址), 加上需要镜像仓库地址
修改之后重启下docker
systemctl restart docker
重启之后,重新拉取就可以了
[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu
Using default tag: latest
latest: Pulling from ubuntu
7b1a6ab2e44d: Already exists
Digest: sha256:7cc0576c7c0ec2384de5cbf245f41567e922aab1b075f3e8ad565f508032df17
Status: Downloaded newer image for 192.168.245.133:5000/ubuntu:latest
192.168.245.133:5000/ubuntu:latest
Q: push到本地仓库为啥使用localhost,能使用本地ip吗?
A:当然可以使用本地ip
# 当前机器ip 192.168.245.133
[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu:latest
Error response from daemon: Get https://192.168.245.133:5000/v2/: http: server gave HTTP response to HTTPS client
可以发现直接push会报错,报错跟上面的报错内容一样
此时会把本机的ip地址当成不安全的ip,所以push不上去,配置下,允许本机不安全的ip注册
配置方式跟上面一样,将本机的注册地址加到insecure-registries 配置里面即可
{
"insecure-registries":["192.168.245.133:5000"],
"registry-mirrors": ["https://9fgss2yh.mirror.aliyuncs.com"]
}
然后重启docker
[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu:latest
latest: Pulling from ubuntu
Digest: sha256:7cc0576c7c0ec2384de5cbf245f41567e922aab1b075f3e8ad565f508032df17
Status: Downloaded newer image for 192.168.245.133:5000/ubuntu:latest
此时就push成功了
运行 docker-registry-web 镜像
可参考:https://hub.docker.com/r/hyper/docker-registry-web
$ docker run -it -p 5001:8080 --name registry-web -d --restart always --link registry -e REGISTRY_URL=http://registry:5000/v2 -e REGISTRY_NAME=localhost:5000 hyper/docker-registry-web
然后访问5001端口:http://192.168.245.133:5001/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App