archer05 发表于 2018-5-26 06:28:21

【docker】通过仓库共享镜像

  通过仓库共享镜像
  本地仓库
  在本地建一个仓库,可以上传和下载做好的docker镜像。
  用 git 下载源码后修改配置文件 config.yml,把 storage_path 部分改成 Docker 镜像仓库的存放地点:

$ git clone https://github.com/dotcloud/docker-registry.git
$ cd docker-registry
$ cp config_sample.yml config.yml
$ vi config.yml
...
# this is the default configuration when no flavor id specified
dev:
storage: local
storage_path: /home/vpsee/registry
loglevel: debug
...
  $ mkdir /home/vpsee/registry
$ pip install -r requirements.txt
$ gunicorn --access-logfile - --log-level debug --debug -b 0.0.0.0:5000 -w 1 wsgi:application
或者$ gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:80 -w 1 wsgi:application


  打开浏览器,访问 IP 地址就可以看到 docker-registry 私有仓库在运行了。
  查看一下系统已经有了哪些镜像

$ sudo docker images
REPOSITORY      TAG      ID            CREATED         SIZE
vpsee/ubuntu    latest   936a54e8a345    2 weeks ago   12.29 kB (virtual 327.8 MB)
ubuntu          latest   8dbd9e392a96    6 months ago    131.5 MB (virtual 131.5 MB)
  我们打算把 vpsee/ubuntu 这个镜像(ID 是 936a54e8a345)上传(push)到我们刚创建的私有仓库里(这个私有仓库的 IP 地址是 192.168.2.45),会看到提示 Username/Password,初次 push 的话,可以自己设置用户名和密码:

$ sudo docker tag 936a54e8a345 192.168.2.45/vpsee
$ sudo docker push 192.168.2.45/vpsee
Username: vpsee
Password:
Email: docker@vpsee.com
Account created. Please use the confirmation link we sent to your e-mail to activate it.
The push refers to a repository (len: 1)
Processing checksums
Sending image list
Pushing repository 192.168.2.45/vpsee (1 tags)
Pushing 8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c
Buffering to disk 58266504/? (n/a)
Pushing 58.27 MB/58.27 MB (100%)
  完成 push 后,我们的私有仓库就有了第一个镜像了:


$ sudo docker images
REPOSITORY          TAG      ID             CREATED      SIZE
vpsee/ubuntu      latest   936a54e8a345   2 weeks ago    12.29 kB (virtual 327.8 MB)
ubuntu            latest   8dbd9e392a96   6 months ago   131.5 MB (virtual 131.5 MB)
ubuntu            precise8dbd9e392a96   6 months ago   131.5 MB (virtual 131.5 MB)

  以后只要 docker pull 192.168.2.45/vpsee 就可以从我们自己的私有仓库下载和运行镜像了,本地网络速度当然会快很多。
  公共仓库
  在docker 的index上创建用户,供上传和下载镜像。
页: [1]
查看完整版本: 【docker】通过仓库共享镜像