在Docker生态圈中,Docker仓库用于存储Docker镜像。官方的Docker hub存储了大量镜像,但是对于实际生产环境中,考虑到pull/push速度和保密性等因素,我们往往需要建立自己的镜像仓库服务。官方(docker-registry github )提供了一个registry images,使用这个images就可以快速完成本地镜像仓库的建立。
通过下面命令将最新的registry images拉下来:
1 |
# docker pull registry:latest |
启动registry,这里使用本地目录作为存储,并将服务映射到主机的5000端口上。
1 2 |
# 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已经运行
1 2 3 |
# 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服务运行状态:
1 2 |
# curl 127.0.0.1:5000 "\"docker-registry server\"" |
然后可以使用tag命令把一个images标记到本地仓库中,并将本机的镜像上传到该仓库中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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已经被成功上传。
1 2 3 4 |
# ls /var/lib/docker/registry/images ...... d7e093c2d1424b2574368a574e91b859ee52bb4a2fa5f9a3d73b4e9da4f68d5c ...... |
测试从本地registry中pull下image。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 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来操作。
1 2 3 4 5 6 7 |
#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" ....... |
^^
这娃娃哪里能买到
其实这应该是虫子吃过了的部分,是排泄物,很松软,容易挖开