1. 程式人生 > >Docker私有倉庫映象上傳下載

Docker私有倉庫映象上傳下載

建立好私有倉庫之後,就可以使用 docker tag 來標記一個映象,然後推送它到倉庫,別的機器上就可以下載下來了。例如私有倉庫地址為 192.168.7.26:5000。
先在本機檢視已有的映象。
$ docker images
REPOSITORY      TAG     IMAGE ID   CREATED    VIRTUAL SIZE
ubuntu       latest    ba5877dc9bec  6 weeks ago   192.7 MB
ubuntu       14.04    ba5877dc9bec  6 weeks ago   192.7 MB

使用docker tag 將 ba58 這個映象標記為 192.168.7.26:5000/test(格式為 docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG])。
$ docker tag ba58 192.168.7.26:5000/test
$ docker images
REPOSITORY      TAG     IMAGE ID   CREATED    VIRTUAL SIZE
ubuntu       14.04    ba5877dc9bec  6 weeks ago   192.7 MB
ubuntu       latest    ba5877dc9bec  6 weeks ago   192.7 MB
192.168.7.26:5000/test   latest    ba5877dc9bec  6 weeks ago   192.7 MB

使用 docker push 上傳標記的映象。

$ docker push 192.168.7.26:5000/test
The push refers to a repository [192.168.7.26:5000/test] (len: 1)
Sending image list
Pushing repository 192.168.7.26: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.7.26:5000/v1/repositories/test/tags/latest}

用 curl 檢視倉庫中的映象。

$ curl http://192.168.7.26:5000/v1/search
{"num_results": 7, "query": "", "results":
[{"description": "", "name": "library/miaxis_j2ee"},
 {"description": "", "name": "library/tomcat"},
 {"description": "", "name": "library/ubuntu"},
 {"description": "", "name": "library/ubuntu_office"},
 {"description": "", "name": "library/desktop_ubu"},
 {"description": "", "name": "dockerfile/ubuntu"},
 {"description": "", "name": "library/test"}]}
這裡可以看到 {"description": "", "name": "library/test"},表明映象已經被成功上傳了。

現在可以到另外一臺機器去下載這個映象

$ docker pull 192.168.7.26:5000/test
Pulling repository 192.168.7.26:5000/test
ba5877dc9bec: Download complete
511136ea3c5a: Download complete
9bad880da3d2: Download complete
25f11f5fb0cb: Download complete
ebc34468f71d: Download complete
2318d26665ef: Download complete

$ docker images
REPOSITORY       TAG     IMAGE ID   CREATED    VIRTUAL SIZE
192.168.7.26:5000/test    latest    ba5877dc9bec  6 weeks ago   192.7 MB

用curl檢視倉庫的映象列表
$ curl http://192.168.100.171:5000/v2/_catalog
{"repositories":["docker/myhttpd","docker/mynginx","docker/mysql-master","docker/mysql-slave"]}

用curl檢視映象的tag列表
$ curl http://192.168.100.171:5000/v2/docker/myhttpd/tags/list    
{"name":"docker/httpd","tags":["1.0","2.0"]}