首页 > 代码库 > 搭建私有Docker Registry
搭建私有Docker Registry
Docker的Docker Hub是一个公有的Registry, 从Docker Hub上可以找到很多的官方或个人构建的Docker Image, 通常, 这些image能满足开发、测试的需求. 但是如果想构建的image只在控制范围内共享, 而不是开放环境, 那就得搭建自己的私有Docker Registry. Docker官方实现了docker-registy, 根据官方的说明可以搭建自己的Docker Registry, 官方有两种方式搭建Docker Registry, 一种是按传统的部署软件的方法安装Docker Registry, 详细可参考Matthew Fisher的博客, 另一种是通过官方构建的Docker image来搭建Docker Registry. 本文简单介绍如何通过官方Docker image搭建自己的私有Docker Registry.
第一步: 下载官方Registry Docker Image
docker pull registry:latest
第二步: 准备配置文件
创建配置文件
Docker Registry自带一个config_sample.yml配置文件, 通常将这个文件重命名为config.yml作为基本配置文件.
配置flavors
Docker Registry可以以几种flavors运行, 这使得Docker Registry可以运行在开发模式, 产线模式或者自定义的模式. 从配置文件config_sample.yml可知包括如下的一些flavors.
common: 作为其他flavors的基本配置.
local: 将数据存放在本地文件系统.
s3: 使用AWS S3存放数据.
dev: 使用local flavor作为基本配置.
test: 作为单元测试的flavor.
prod: 默认使用s3 flavor作为产线配置.
除此之外, 也可以使用OpenStack的swift, glance, glance-swift来存放数据, 还有key/value存储elliptics, 以及Google Cloud Storage GCE来存放数据. 除前所述的内置flavors, 也可以自定义flavor. 下面是一个简单config.yml配置文件:
common: loglevel: info search_backend: "_env:SEARCH_BACKEND:"sqlalchemy_index_database:"_env:SQLALCHEMY_INDEX_DATABASE:sqlite:////tmp/docker-registry.db"prod: loglevel: warn storage: s3 s3_access_key: _env:AWS_S3_ACCESS_KEY s3_secret_key: _env:AWS_S3_SECRET_KEY s3_bucket: _env:AWS_S3_BUCKET boto_bucket: _env:AWS_S3_BUCKET storage_path: /srv/docker smtp_host: localhost from_addr: docker@myself.com to_addr: my@myself.com dev: loglevel: debug storage: local storage_path: /home/myself/docker test: storage: local storage_path: /tmp/tmpdockertmpDocker Registry的默认运行环境是dev, 如果你需要更改运行环境, 可通过环境变量SETTINGS_FLAVOR来指定, 例如, 通过执行如下可设定运行环境为prod.
export SETTINGS_FLAVOR=prod
指定配置文件位置
Docker Registry运行时可以通过环境变量DOCKER_REGISTRY_CONFIG指定config.yml的默认路径, 例如指定config.yml的默认位置为/opt/docker-registry/conf如下:
export DOCKER_REGISTRY_CONFIG=/opt/docker-registy/conf/config.yml
配置选项
通用配置选项包括loglevel, debug_versions, storage_redirect等, 其中logleve可以设置为info, debug, warn, error和critical级别.
# Default log level is infologlevel: _env:LOGLEVEL:info授权选项包括standalone, index_endpoint和disable_token_auth等, standalone用来设定Docker Registry server为stand-alone模式, index_endpoint配置index endpoint的hostname, 通常用来验证用户登录时的密码, 默认是https://index.docker.io.
# By default, the registry acts standalone (eg: doesn‘t query the index)standalone: _env:STANDALONE:true# The default endpoint to use (if NOT standalone) is index.docker.ioindex_endpoint: _env:INDEX_ENDPOINT:https://index.docker.io# Token auth is enabled (if NOT standalone)disable_token_auth: _env:DISABLE_TOKEN_AUTH搜索引擎选项
search_backend用来设定后台搜索引擎, 如果为空, 则没有索引, 当前支持的backend为sqlalchemy.
# No search backendsearch_backend: _env:SEARCH_BACKEND# SQLite search backendsqlalchemy_index_database: _env:SQLALCHEMY_INDEX_DATABASE:sqlite:////tmp/docker-registry.db存储选项storage设置存储引擎, Docker Registry默认存储引擎为file和s3, 也可以通过pip install docker-registry-driver-STORAGE_NAME来安装其他storage, 比如swift, gcs, glance等, 然后配置storage为STORAGE_NAME, 跟storage选项一起使用的是storage_path, 其用来指定存储数据的路径, 比如: /registry.
local: storage: file storage_path: /mnt/registry prod: storage: s3 s3_region: us-west-1 s3_bucket: acme-docker storage_path: /registry s3_access_key: AKIAHSHB43HS3J92MXZ s3_secret_key: xdDowwlK7TJajV1Y7EoOZrmuPEJlHYcNP2k4j49T
第三步: 运行Docker Registry
准备Docker Registry的配置文件路径以及在dev, test, prod模式下存放images的路径.
mkdir -p /opt/docker-registry/{conf,dev,test,prod}
配置config.yml文件如下:
# All other flavors inherit the `common‘ config snippetcommon: &common# Default log level is info loglevel: _env:LOGLEVEL:info# Enable the debugging /_versions endpoint debug_versions: _env:DEBUG_VERSIONS:false# By default, the registry acts standalone (eg: doesn‘t query the index) standalone: _env:STANDALONE:true# The default endpoint to use (if NOT standalone) is index.docker.io index_endpoint: _env:INDEX_ENDPOINT:https://index.docker.io# Storage redirect is disabled storage_redirect: _env:STORAGE_REDIRECT# Token auth is enabled (if NOT standalone) disable_token_auth: _env:DISABLE_TOKEN_AUTH# No priv key privileged_key: _env:PRIVILEGED_KEY# No search backend search_backend: _env:SEARCH_BACKEND# SQLite search backend sqlalchemy_index_database: _env:SQLALCHEMY_INDEX_DATABASE:sqlite:////tmp/docker-registry.db# Enable bugsnag (set the API key) bugsnag: _env:BUGSNAG local: &local<<: *common storage: local# This is the default configuration when no flavor is specifieddev: &dev<<: *local loglevel: _env:LOGLEVEL:debug debug_versions: _env:DEBUG_VERSIONS:true search_backend: _env:SEARCH_BACKEND:sqlalchemy storage_path: _env:STORAGE_PATH:/opt/docker-registry/dev# This flavor is used by unit teststest:<<: *dev standalone: true storage_path: _env:STORAGE_PATH:/opt/docker-registry/test# To specify another flavor, set the environment variable SETTINGS_FLAVOR# $ export SETTINGS_FLAVOR=prodprod:<<: *dev storage_path: _env:STORAGE_PATH:/opt/docker-registry/prod
运行Docker Registry(dev模式)
docker run -p 5000:5000 -v /opt/docker-registry/conf/:/opt/docker-registry/conf/ -v /opt/docker-registry/dev:/opt/docker-registry/dev --name=test-docker-registry -e DOCKER_REGISTRY_CONFIG=/opt/docker-registry/conf/config.yml registry其中设置volume /opt/docker-registry/dev为本地数据存储目录, –e DOCKER_REGISTRY_CONFIG=/opt/docer-registry/conf/config.yml为配置文件, 最后运行输出如下:
2014-09-16 15:02:28,547 WARNING: Cache storage disabled!2014-09-16 15:02:28,548 WARNING: LRU cache disabled!2014-09-16 15:02:28,553 DEBUG: Will return docker-registry.drivers.file.Storage2014-09-16 15:02:29 [1] [INFO] Starting gunicorn 18.02014-09-16 15:02:29 [1] [INFO] Listening at: http://0.0.0.0:5000 (1)2014-09-16 15:02:29 [1] [INFO] Using worker: gevent2014-09-16 15:02:29 [14] [INFO] Booting worker with pid: 142014-09-16 15:02:29 [15] [INFO] Booting worker with pid: 152014-09-16 15:02:29 [18] [INFO] Booting worker with pid: 182014-09-16 15:02:29 [19] [INFO] Booting worker with pid: 192014-09-16 15:02:29,361 WARNING: Cache storage disabled!2014-09-16 15:02:29,362 WARNING: LRU cache disabled!2014-09-16 15:02:29,374 DEBUG: Will return docker-registry.drivers.file.Storage2014-09-16 15:02:29,575 WARNING: Cache storage disabled!2014-09-16 15:02:29,576 WARNING: LRU cache disabled!2014-09-16 15:02:29,578 DEBUG: Will return docker-registry.drivers.file.Storage2014-09-16 15:02:29,595 WARNING: Cache storage disabled!2014-09-16 15:02:29,596 WARNING: LRU cache disabled!2014-09-16 15:02:29,598 DEBUG: Will return docker-registry.drivers.file.Storage2014-09-16 15:02:29,628 WARNING: Cache storage disabled!2014-09-16 15:02:29,629 WARNING: LRU cache disabled!2014-09-16 15:02:29,631 DEBUG: Will return docker-registry.drivers.file.Storage上传image:
docker tag busybox 10.224.106.43:5000/busybox [root@golang dev]# docker push 10.224.106.43:5000/busyboxThe push refers to a repository [10.224.106.43:5000/busybox] (len: 1) Sending image list Pushing repository 10.224.106.43:5000/busybox (1 tags) 511136ea3c5a: Image successfully pushed 42eed7f1bf2a: Image successfully pushed 120e218dd395: Image successfully pushed a9eb17255234: Image successfully pushed Pushing tag for rev [a9eb17255234] on {http://10.224.106.43:5000/v1/repositories/busybox/tags/latest}与此同时, 你能在Docker Registry container运行的终端看到上传busybox的日志记录, 如:
10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/_ping HTTP/1.1" 200 4 "-" "Go 1.1 package http"2014-09-16 15:07:54,129 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/_ping HTTP/1.1" 200 4 "-" "Go 1.1 package http"2014-09-16 15:07:54,133 DEBUG: args = {‘namespace‘: ‘library‘, ‘repository‘: u‘busybox‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/repositories/busybox/ HTTP/1.1" 200 2 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,167 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/repositories/busybox/ HTTP/1.1" 200 2 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,170 DEBUG: args = {‘image_id‘: u‘511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158‘}2014-09-16 15:07:54,172 DEBUG: api_error: Image not found10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,173 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,174 DEBUG: args = {‘image_id‘: u‘511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,176 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,260 DEBUG: args = {‘image_id‘: u‘511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,262 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,263 DEBUG: args = {‘image_id‘: u‘511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,265 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,266 DEBUG: args = {‘image_id‘: u‘42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229‘}2014-09-16 15:07:54,267 DEBUG: api_error: Image not found10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,268 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,269 DEBUG: args = {‘image_id‘: u‘42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,271 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,322 DEBUG: args = {‘image_id‘: u‘42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,324 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,325 DEBUG: args = {‘image_id‘: u‘42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,327 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/42eed7f1bf2ac3f1610c5e616d2ab1ee9c7290234240388d6297bc0f32c34229/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,328 DEBUG: args = {‘image_id‘: u‘120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16‘}2014-09-16 15:07:54,329 DEBUG: api_error: Image not found10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,329 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "GET /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,331 DEBUG: args = {‘image_id‘: u‘120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16‘}10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,333 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:54] "PUT /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:54,566 DEBUG: args = {‘image_id‘: u‘120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16‘}10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,105 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,107 DEBUG: args = {‘image_id‘: u‘120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16‘}10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,109 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/120e218dd395ec314e7b6249f39d2853911b3d6def6ea164ae05722649f34b16/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,111 DEBUG: args = {‘image_id‘: u‘a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721‘}2014-09-16 15:07:55,112 DEBUG: api_error: Image not found10.224.106.43 - - [16/Sep/2014:15:07:55] "GET /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,112 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "GET /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/json HTTP/1.1" 404 28 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,114 DEBUG: args = {‘image_id‘: u‘a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721‘}10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,116 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/json HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,197 DEBUG: args = {‘image_id‘: u‘a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721‘}10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,199 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/layer HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,201 DEBUG: args = {‘image_id‘: u‘a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721‘}10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,202 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/images/a9eb172552348a9a49180694790b33a1097f546456d041b6e82e4d7716ddb721/checksum HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,203 DEBUG: args = {‘tag‘: u‘latest‘, ‘namespace‘: ‘library‘, ‘repository‘: u‘busybox‘}2014-09-16 15:07:55,204 DEBUG: [put_tag] namespace=library; repository=busybox; tag=latest10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/repositories/busybox/tags/latest HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,205 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/repositories/busybox/tags/latest HTTP/1.1" 200 4 "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,206 DEBUG: args = {‘images‘: True, ‘namespace‘: ‘library‘, ‘repository‘: u‘busybox‘}10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/repositories/busybox/images HTTP/1.1" 204 - "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"2014-09-16 15:07:55,232 INFO: 10.224.106.43 - - [16/Sep/2014:15:07:55] "PUT /v1/repositories/busybox/images HTTP/1.1" 204 - "-" "docker/1.0.0 go/go1.2.2 kernel/3.10.0-123.el7.x86_64 os/linux arch/amd64"除此之外你也可以在浏览器上输入http://10.224.106.43:5000看到Docker Registry的运行模式, 当前运行模式为dev, 其输出信息如"docker-registry server (dev) (v0.8.1)".这时在/opt/docker-registry/dev目录下, 你能看到两个新的目录images和repositories, 这是新上传busybox的信息. 而且你可以在其他机器上从Docker Registry(10.224.106.43)上下载刚上传的image. 如:
[root@docker02 ~]# docker pull 10.224.106.43:5000/busyboxPulling repository 10.224.106.43:5000/busybox a9eb17255234: Download complete 511136ea3c5a: Download complete 42eed7f1bf2a: Download complete 120e218dd395: Download complete
运行Docker Registry(prod模式)
通过环境变量
SETTINGS_FLAVOR使得Docker Registry以prod模式运行, 运行命令如:
docker run -d -p 5000:5000 -v /opt/docker-registry/conf/:/opt/docker-registry/conf/ -v /opt/docker-registry/prod:/opt/docker-registry/prod --name=test-docker-registry -e DOCKER_REGISTRY_CONFIG=/opt/docker-registry/conf/config.yml -e SETTINGS_FLAVOR=prod registry这时如果上传image,你能在/opt/docker-registry/prod下发现新上传的image数据, 而且也可以从其他机器下载新上传的image.
[root@golang conf]# docker push 10.224.106.43:5000/busyboxThe push refers to a repository [10.224.106.43:5000/busybox] (len: 1) Sending image list Pushing repository 10.224.106.43:5000/busybox (1 tags) 511136ea3c5a: Image successfully pushed 42eed7f1bf2a: Image successfully pushed 120e218dd395: Image successfully pushed a9eb17255234: Image successfully pushed Pushing tag for rev [a9eb17255234] on {http://10.224.106.43:5000/v1/repositories/busybox/tags/latest} [root@golang prod]# pwd/opt/docker-registry/prod [root@golang prod]# lltotal 4drwxr-xr-x. 6 root root 4096 Sep 16 11:36 images drwxr-xr-x. 3 root root 20 Sep 16 11:36 repositories [root@docker02 ~]# docker pull 10.224.106.43:5000/busyboxPulling repository 10.224.106.43:5000/busybox a9eb17255234: Download complete 511136ea3c5a: Download complete 42eed7f1bf2a: Download complete 120e218dd395: Download complete
参考资料
https://github.com/docker/docker-registry
http://www.activestate.com/blog/2014/01/deploying-your-own-private-docker-registry
本文出自 “大脑原来不靠谱” 博客,请务必保留此出处http://aresy.blog.51cto.com/5100031/1553624
搭建私有Docker Registry