docker 建立私有仓库

有时候docker拉镜像的确有很慢哈,官方也考虑到这一点了,所以呢,允许你建立自己的私有仓库,以下只是简单创建,没有考虑安全性问题

三步骤

拉取

1
docker pull registry

根据下载的镜像创建并运行一个容器

1
docker run -p 5000:5000 -v /data/registry:/var/lib/registry --name registry -d registry
  • -p选项用于将宿主机的端口映射到容器的端口,这样就可以通过宿主机的地址访问容器服务
  • -v选项用于将宿主机的目录挂在到容器的目录,便于直接在宿主机上查看上传的镜像

访问 http://xxx.xxxx.xxx:5000/v2,你会在网页看到一个{},说明建立成功了

上传镜像到私有仓库

通过 docker tag 将该镜像标志为要推送到私有仓库

docker tag 镜像名[:标签] 镜像仓库服务器地址/命名空间/镜像发布名:发布标签,
运行 docker pus 将镜像 push 到我们的私有仓库中

docker push 镜像仓库服务器地址/命名空间/镜像发布名:发布标签
本例中,我们操作如下

1
2
docker tag php xxx.xxx.xxx:5000/php
docker push xxx.xxx.xxx:5000/php

如果遇到一下问题

http: server gave HTTP response to HTTPS client

对应的解决方法

请修改改文件 /etc/docker/daemon.json

{ “insecure-registries”:[“myregistry.example.com:5000”] }

1
2
3
systemctl restart docker.service

docker restart registry

然后在此 push,完毕后

然后在 /data/registry/docker/registry/v2/repositories/php 查看到改该镜像
以上假设是在某台服务器上的操作,现在另外一台服务准备拉取镜像,不经过官方的

1
docker pull xxx.xxx.xxx:5000/php

可能会出现上面同样的错误解决办法是一样的

http: server gave HTTP response to HTTPS client

这样就可以了