创建自有仓库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建自有仓库相关的知识,希望对你有一定的参考价值。
如果要外部推送镜像给其他机器在/etc/sysconfig/docker配置文件增加这行:
DOCKER_OPTS="$DOCKER_OPTS --insecure-registry 10.50.103.149:5000"
注意:/etc/init.d/docker脚本中启动时的变量名和上面的要对应
http://debugo.com/docker-registry/
在Docker生态圈中,Docker仓库用于存储Docker镜像。官方的Docker hub存储了大量镜像,但是对于实际生产环境中,考虑到pull/push速度和保密性等因素,我们往往需要建立自己的镜像仓库服务。官方(docker-registry github )提供了一个registry images,使用这个images就可以快速完成本地镜像仓库的建立。
通过下面命令将最新的registry images拉下来:
docker pull registry:latest
启动registry,这里使用本地目录作为存储,并将服务映射到主机的5000端口上。
mkdir /var/lib/docker/registry
docker run -e STORAGE_PATH=/registry -e SETTINGS_FLAVOR=local -p 5000:5000 -v /var/lib/docker/registry:/registry -d --name registry_instance registry
此时docker registry已经运行
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e1efcb6528a5 registry:latest docker-registry 21 seconds ago Up 21 seconds 0.0.0.0:5000->5000/tcp registry_instance
检测http服务运行状态:
curl 127.0.0.1:5000
""docker-registry server""
然后可以使用tag命令把一个images标记到本地仓库中,并将本机的镜像上传到该仓库中。
docker tag --help
Usage: docker tag [OPTIONS] IMAGE [REGISTRYHOST/][USERNAME/]NAME[:TAG]
Tag an image into a repository
-f, --force=false Force
docker tag d7e093c2d142 127.0.0.1:5000/r-base1
docker push 127.0.0.1:5000/r-base1
Sending image list
Pushing repository 127.0.0.1:5000/r-base1 (1 tags)
511136ea3c5a: Image successfully pushed
16386e29a1f4: Image successfully pushed
835c4d274060: Image successfully pushed
f4aea4c855b4: Image successfully pushed
150558ab7920: Image successfully pushed
3014084084eb: Image successfully pushed
3f05faa961db: Image successfully pushed
e016bcb13dd1: Image successfully pushed
770166a19d4e: Image successfully pushed
072dc882ef86: Image successfully pushed
d6250bff6b61: Image successfully pushed
8679ddb9b43c: Image successfully pushed
d7e093c2d142: Image successfully pushed
Pushing tag for rev [d7e093c2d142] on {http://127.0.0.1:5000/v1/repositories/r-base1/tags/latest}
查看registry挂载的目录,可以看到images已经被成功上传。
ls /var/lib/docker/registry/images
......
d7e093c2d1424b2574368a574e91b859ee52bb4a2fa5f9a3d73b4e9da4f68d5c
......
测试从本地registry中pull下image。
docker pull 127.0.0.1:5000/r- base1
Pulling repository 127.0.0.1:5000/r-base1
d7e093c2d142: Download complete v1/ 93c2d142: Pulling image (latest) from 127.0.0.1:5000/r-base1
511136ea3c5a: Download complete
16386e29a1f4: Download complete
835c4d274060: Download complete
f4aea4c855b4: Download complete
150558ab7920: Download complete
3014084084eb: Download complete
3f05faa961db: Download complete
e016bcb13dd1: Download complete
770166a19d4e: Download complete
072dc882ef86: Download complete
d6250bff6b61: Download complete
同样,通过查看registry的日志,可以看到images通过PUT/GET来操作。
#docker logs e1efcb6528a5
......
10.0.42.1 - - [19/Jan/2015:07:40:59 +0000] "PUT /v1/images/d7e093c2d1424b2574368a574e91b859ee52bb4a2fa5f9a3d73b4e9da4f68d5c/json HTTP/1.1" 200 4 "-" "docker/1.0.1 go/go1.2.1 git-commit/990021a kernel/3.13.0-32-generic os/linux arch/amd64"
10.0.42.1 - - [19/Jan/2015:07:40:59 +0000] "PUT /v1/images/d7e093c2d1424b2574368a574e91b859ee52bb4a2fa5f9a3d73b4e9da4f68d5c/layer HTTP/1.1" 200 4 "-" "docker/1.0.1 go/go1.2.1 git-commit/990021a kernel/3.13.0-32-generic os/linux arch/amd64"
......
10.0.42.1 - - [19/Jan/2015:07:46:50 +0000] "GET /v1/images/d7e093c2d1424b2574368a574e91b859ee52bb4a2fa5f9a3d73b4e9da4f68d5c/ancestry HTTP/1.1" 200 884 "-" "docker/1.0.1 go/go1.2.1 git-commit/990021a kernel/3.13.0-32-generic os/linux arch/amd64"
.......
^^
以上是关于创建自有仓库的主要内容,如果未能解决你的问题,请参考以下文章