LoginSignup
7
8

More than 5 years have passed since last update.

Docker Private Regisrty2.0を認証付きでさくっと動かす

Last updated at Posted at 2015-08-09

概要

Docker Private Registry2.0の認証付きです。
Registryはv1とv2の2種類存在します。
dokcerのバージョンが1.6以降ならv2に対応してます

前回の認証なしはこちらを参照

環境

  • Boot2Docker 1.7.0
  • Mac Pro Yosemite

reg.loというHostで準備していく

$ mkdir registry
$ cd registry
$ sudo vi /etc/hosts
192.168.59.103 reg.lo
$ boot2docker start
$ eval "$(boot2docker shellinit)"

鍵作成、CN=reg.loを設定する

$ mkdir -p certs && openssl req \
    -newkey rsa:4096 -nodes -sha256 -keyout certs/docker-registry.key \
    -x509 -days 365 -out certs/docker-registry.crt

Generating a 4096 bit RSA private key
.............................................................++
...................................................................++
writing new private key to 'certs/docker-registry.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:reg.lo
Email Address []:

鍵をboot2dockerに設置(クライアントのdockerへの設定)

$ boot2docker ssh
$ cd /var/lib/boot2docker
$ sudo vi bootsync.sh
#!/bin/sh
echo "192.168.59.103 reg.lo" >> /etc/hosts
cat /var/lib/boot2docker/reg.lo.pem >> /etc/ssl/certs/ca-certificates.crt

$ sudo chmod +x bootsync.sh
// boot2dockerはUsersがMountされているのでそこから取得
$ sudo cp /Users/xxx/registry/certs/docker-registry.crt ./reg.lo.pem
$ exit
$ boot2docker ssh sudo /etc/init.d/docker restart

pem の読み込みの挙動があやしいのでcertificates.crtに直接書き込むことにした。
前回のProxyを挟まない場合はpemでも正常動作する。

永続化(内容だけみると起動時反映処理ですが。。)することで$ boot2docker start時に動的に設定が読み込まれる
なお、上記永続化はdocker v1.6以降のやり方になる

永続化の参照

registryを実行

$ docker run -d -v $(pwd)/data:/tmp/registry-dev --name docker-registry registry:2.0

適当にユーザーとパスワード設定

$ htpasswd -c .htpasswd hoge

NginxなProxyを実行

$ docker run -d -p 443:443 \
  -e REGISTRY_HOST="docker-registry" \
  -e REGISTRY_PORT="5000" \
  -e SERVER_NAME="reg.lo" \
  --link docker-registry:docker-registry \
  -v $(pwd)/.htpasswd:/etc/nginx/.htpasswd:ro \
  -v $(pwd)/certs:/etc/nginx/ssl:ro \
  --name docker-registry-proxy \
  containersol/docker-registry-proxy

nginxの設定はこちらを参照
http://container-solutions.com/running-secured-docker-registry-2-0/

接続テスト

$ docker pull hello-world
$ docker tag hello-world reg.lo:443/hello-world 
$ docker push reg.lo:443/hello-world
The push refers to a repository [reg.lo:443/hello-world] (len: 1)
91c95931e552: Image push failed 

Please login prior to push:
Username: hoge
Password: 
Email: 
WARNING: login credentials saved in /Users/xxx/.docker/config.json
Login Succeeded
The push refers to a repository [reg.lo:443/hello-world] (len: 1)
91c95931e552: Image already exists 
a8219747be10: Image successfully pushed 
Digest: sha256:2b471673e2552749332efa8cac83d4635dce8c276637d630e4c85ac99b4700be

メモ

フロントエンドのUIも試したかったけど、Issue見るとまだ2.0には対応してない模様
マイルストーンでも眺めるか。。
https://github.com/kwk/docker-registry-frontend/milestones

Search機能がうまく動かない。これもバグっぽい

7
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8