搭建私有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: [email protected]
    to_addr: [email protected]

dev:
    loglevel: debug
    storage: local
    storage_path: /home/myself/docker

test:
    storage: local
    storage_path: /tmp/tmpdockertmp

Docker 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

[[email protected] 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. 如:

[[email protected] ~]# 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.

[[email protected] 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}

[[email protected] prod]# pwd/opt/docker-registry/prod
[[email protected] 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

[[email protected] ~]# 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
参考资料
  1. https://github.com/docker/docker-registry
  2. http://www.activestate.com/blog/2014/01/deploying-your-own-private-docker-registry
时间: 2024-10-13 09:45:10

搭建私有Docker Registry的相关文章

Docker Registry使用:公有Docker Registry使用、私有Docker Registry的搭建

公有Docker Registry的操作 首先必须注册自己的dockerhub账号,假设为simpledockerhub [[email protected] ]# docker login --默认即https://hub.docker.com Username : simpledockerhub Password: ***** Login Succeeded [[email protected] ]# docker pull hello-world [[email protected] ]#

创建私有Docker Registry的坑

1.创建私有docker registry: docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry --name registry registry:2 清理过期容器的shell脚本: #!/bin/bashdocker stop $(docker ps -a -q)docker rm $(docker ps -a -q) 2.创建docker registry,假如不使用默认的https格式,那么所有的客户端和服务端必须设

搭建本地docker registry

搭建本地docker registry: docker pull registry:2 mkdir /home/registry docker run -d -p 5000:5000 --name registry -v /home/registry:/var/lib/registry registry:2 docker ps -a netstat -ntpl | grep 5000 上传image到docker hub: docker tag ubuntu:16.04 localhost:50

10.部署私有 docker registry

10.部署私有 docker registry 注意:本文档介绍使用 docker 官方的 registry v2 镜像部署私有仓库的步骤,你也可以部署 Harbor 私有仓库(部署 Harbor 私有仓库). 本文档讲解部署一个 TLS 加密.HTTP Basic 认证.用 ceph rgw 做后端存储的私有 docker registry 步骤,如果使用其它类型的后端存储,则可以从 “创建 docker registry” 节开始: 示例两台机器 IP 如下: ceph rgw: 192.1

Docker搭建私有仓库registry

拉取上传镜像 拉取镜像 docker pull <registry>[:<port>]/[<namespace>/]<name>:<tag> # registry :仓库服务器地址;不指定默认是docker hub # port :端口;默认443,因为是https协议: # namespace :名称空间,指是哪个用户的仓库,如果是顶层仓库,可以省: # name :仓库名: # tag :标签名:默认是latest版本: 上传镜像 docke

搭建企业级Docker Registry -- Harbor

Harbor 是一个企业级的 Docker Registry,可以实现 images 的私有存储和日志统计权限控制等功能,并支持创建多项目(Harbor 提出的概念),基于官方 Registry V2 实现. 下面为搭建过程: 1.安装docker,过程略. 2.安装docker-compose # curl -L https://github.com/docker/compose/releases/download/1.7.0/docker-compose-`uname -s`-`uname

搭建私服-docker registry

Docke官方提供了Docker Hub网站来作为一个公开的集中仓库.然而,本地访问Docker Hub速度往往很慢,并且很多时候我们需要一个本地的私有仓库只供网内使用.Docker仓库实际上提供两方面的功能,一个是镜像管理,一个是认证.前者主要由docker-registry项目来实现,通过http服务来上传下载:后者可以通过docker-index(闭源)项目或者利用现成认证方案(如nginx)实现http请求管理. 系统环境:CentOS 7.2主机IP:192.168.116.148 1

搭建私有 Docker 仓库服务器

Docker Hub 是 Docker 官方的公共仓库服务器,用户在 DockerHub 上只能创建一个私有仓库,这对于有些用户是不够用的,而且 DockerHub 服务器的访问速度也是个很大问题,那么我们希望能在自己本地的服务器上创建一个类似于 DockerHub 仓库服务器供团队使用,这也是可以的. 我测试的环境是 Mac OSX 下,已经通过 Boot2Docker 工具安装好 Docker 的环境,通过 命令boot2docker ip 可以查看虚拟机的 IP 是 192.168.59.

Nexus Repository Manager 搭建私有docker仓库

使用容器安装Nexus3 1.下载nexus3的镜像: docker pull sonatype/nexus3 2.使用镜像启动一个容器: docker run -d --name nexus  --restart=always -p 5000:5000 -p 8081:8081 sonatype/nexus3 注:5000端口是用于镜像仓库的服务端口   8081 端口是nexus的服务端口 3.启动之后我们就可以通过http://服务器IP:8081访问. 默认账号密码为admin/admi