服务器版本 Ubuntu 16.04 LTS。
安装命令:
复制代码 代码如下:
$ docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry
Registry 服务默认会将镜像保存在/var/lib/registry目录下,上面命令设置保存目录在/opt/registry下,我们可以看下 Registry 容器状态:
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e2b1ffd9072e registry "/entrypoint.sh /e..." 2 hours ago Up About an hour 0.0.0.0:5000->5000/tcp stoic_davinci
接着,我们登录另外一台服务器,将本地的已有的镜像文件推送到私有仓库中,首先,我们需要将镜像的tag标记为要推送到私有仓库,示例:
$ docker tag hwapp:v2 40.125.207.78:5000/hwapp:v3
然后,我们看下镜像文件列表:
$ docker images docker images REPOSITORY TAG IMAGE ID CREATED SIZE 40.125.207.78:5000/hwapp v3 fe28b19b4410 24 hours ago 1.63GB hwapp v2 fe28b19b4410 24 hours ago 1.63GB hwapp v1 8a28e2e870d4 25 hours ago 1.63GB microsoft/aspnetcore latest 0f2330f1a843 26 hours ago 280MB microsoft/dotnet latest a7dd4972fc95 6 days ago 1.63GB
最后,我们就可以将40.125.207.78:5000/hwapp:v3镜像文件,推送到私有仓库了:
$ docker push 40.125.207.78:5000/hwapp:v3
可能会出现下面的错误:
$ docker push 40.125.207.78:5000/hwapp:v3
The push refers to a repository [40.125.207.78:5000/hwapp]
Get https://40.125.207.78:5000/v1/_ping: http: server gave HTTP response to HTTPS client
解决方式,在本服务器操作,而不是私有仓库所在服务器(如果已有daemon.json文件,进行修改即可):
$ touch /etc/docker/daemon.json $ echo '{ "insecure-registries": ["40.125.207.78:5000"] }' > /etc/docker/daemon.json $ service docker restart
然后,再执行下推送命令就可以了,我们也可以直接构建成要推送私有仓库的镜像,示例:
$ docker build -t 40.125.207.78:5000/hwapp:v4 .
然后,再执行下推送命令:
$ docker push 40.125.207.78:5000/hwapp:v4
推送成功之后,我们可以检查下私有仓库里的镜像文件:
$ curl http://40.125.207.78:5000/v2/_catalog {"repositories":["hwapp"]} $ curl http://40.125.207.78:5000/v2/hwapp/tags/list {"name":"hwapp","tags":["v3","v4"]}
然后,我们就可以拉取私有仓库里的镜像文件了:
$ docker pull 40.125.207.78:5000/hwapp:v4
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。