若是要外部推送鏡像給其餘機器在/etc/sysconfig/docker配置文件增長這行:
DOCKER_OPTS="$DOCKER_OPTS --insecure-registry 10.50.103.149:5000"linux
注意:/etc/init.d/docker腳本中啓動時的變量名和上面的要對應git
http://debugo.com/docker-registry/
在Docker生態圈中,Docker倉庫用於存儲Docker鏡像。官方的Docker hub存儲了大量鏡像,可是對於實際生產環境中,考慮到pull/push速度和保密性等因素,咱們每每須要創建本身的鏡像倉庫服務。官方(docker-registry github )提供了一個registry images,使用這個images就能夠快速完成本地鏡像倉庫的創建。
經過下面命令將最新的registry images拉下來:github
# docker pull registry:latest
啓動registry,這裏使用本地目錄做爲存儲,並將服務映射到主機的5000端口上。docker
# 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已經運行json
# 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
# curl 127.0.0.1:5000
"\"docker-registry server\""
而後能夠使用tag命令把一個images標記到本地倉庫中,並將本機的鏡像上傳到該倉庫中。tcp
# 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已經被成功上傳。ide
# 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" ....... ^^