Docker 私有仓库

2016-07-18  本文已影响241人  SateZheng

私有仓库

安装私有仓库

默认情况下,仓库会被创建在容器的 /tmp/registry 下。可以通过 -v 参数来将镜像文件存放在本地的指定路径。 例如下面的例子将上传的镜像放到 /opt/data/registry 目录。

sudo docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry

上传镜像

创建好私有仓库之后,就可以使用 docker tag 来标记一个镜像,然后推送它到仓库,别的机器上就可以下载下来了。例如私有仓库地址为 192.168.0.1:5000。

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sate/centos         6.7                 976079dcc3f5        3 days ago          190.6 MB
centos              6.7                 130db9a2a215        2 weeks ago         190.6 MB

使用docker tag 将 976079dcc3f5 这个镜像标记为 192.168.0.1:5000/sate-centos(格式为 docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG])。

$ docker tag 976079dcc3f5 192.168.0.1:5000/sate-centos:test

$ docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
192.168.0.1:5000/sate-centos   test                976079dcc3f5        3 days ago          190.6 MB
sate/centos                       6.7                 976079dcc3f5        3 days ago          190.6 MB
centos                            6.7                 130db9a2a215        2 weeks ago         190.6 MB

使用 docker push 上传标记的镜像。

$ docker push 192.168.0.1:5000/sate-centos
The push refers to a repository [192.168.0.1:5000/sate-centos] (len: 1)
unable to ping registry endpoint https://192.168.0.1:5000/v0/
v2 ping attempt failed with error: Get https://192.168.0.1:5000/v2/: EOF
 v1 ping attempt failed with error: Get https://192.168.0.1:5000/v1/_ping: EOF

注:报错是因为 docker 默认使用https的方式,解决办法如下:

办法: 修改配置文件,使用 http 方式

centos系统:

修改docker的配置文件/etc/sysconfig/docker

# 加入:
INSECURE_REGISTRY='--insecure-registry 192.168.0.1:5000'
# 重启服务
systemctl restart docker

ubuntu系统:

修改docker的配置文件/etc/default/docker

# 加入:
DOCKER_OPTS='--insecure-registry 192.168.0.1:5000'
# 重启服务
service docker start

再次尝试 push 镜像,如下:

$ sudo docker push 192.168.0.1:5000/test
The push refers to a repository [192.168.0.1:5000/test] (len: 1)
Sending image list
Pushing repository 192.168.0.1:5000/test (1 tags)
Image 511136ea3c5a already pushed, skipping
Image 9bad880da3d2 already pushed, skipping
Image 25f11f5fb0cb already pushed, skipping
Image ebc34468f71d already pushed, skipping
Image 2318d26665ef already pushed, skipping
Image ba5877dc9bec already pushed, skipping
Pushing tag for rev [ba5877dc9bec] on {http://192.168.0.1:5000/v1/repositories/test/tags/latest}

push成功后,查看本地目录/opt/data/registry:

root@sate-z:/opt/data/registry# ls
images  repositories

测试

通过私仓的链接地址查看我们刚上传的镜像:

$ curl http://192.168.0.1:5000/v1/search
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/sate-centos"}]}

下载镜像

pull命令来拉取我们的镜像:

$ docker pull 192.168.0.1:5000/sate-centos:test
上一篇下一篇

猜你喜欢

热点阅读