この記事の内容は下記になります。
- 前半: Deploying a registry server の Configure Nginx with a v1 and v2 registry
- 後半: S3をイメージの保存先に変更する設定
Configure Nginx with a v1 and v2 registry
この章は、基本的には Deploying a registry server の Configure Nginx with a v1 and v2 registry に則っています。
ちなみに、同ページにある他のチュートリアルは、手元のMacで動かせませんでした。
下記、未検証ですがメモ。
-
Simple example with the official image
- dockerの通信がデフォでhttpsを使うようなので、httpを利用するようにしないと使えないようです
-
Configure TLS on a registry server
- なんで動かないんだろ?
- 上に同じくHTTPS周り?
Docker Compose のインストール
Docker Private Registry では、Docker Composer を利用しています。
Docker Composerは、アプリケーションが複数のコンテナの集合から成り立っているときに、コンテナ構成の定義・配置を実現するオーケストレーションツールです。
$ curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
Macでは、上記コマンドによりインストールすることができます。
他にもpipを利用する方法もありますが、詳細は Installing Compose を参照して下さい。
"Permission denied" エラーが発生した場合、/usr/local/binディレクトリに書き込み権限がない可能性があります。
その場合は、上記2コマンドをsudo -iコマンドで実行して下さい。
ワーキングスペースの設定(ソースのDLとブランチ切り出し)
ソースのクローン
$ git clone git@github.com:docker/distribution.git
Relaseブランチから作業ブランチを切り出し
remoteのブランチにある、release/2.0
が現在(2015/4/28時点)でのリリースバージョンになっているので、そこから作業用ブランチを切り出します。
(-b
オプションを付けると、ブランチの作成と同時にブランチの移動もできる)
$ git checkout -b my-release origin/release/2.0
HTTPS通信対応
作業ディレクトリに移動
distribution/contrib/compose/nginx
に移動します。
SSH自己証明書の発行
$ openssl req \
-newkey rsa:2048 -nodes -keyout domain.key \
-x509 -days 365 -out domain.crt
国とか色々聞かれますが、適当に答えて下さい。
Dockerfileの編集
下記をDockerfile
に追記します。
COPY domain.crt /etc/nginx/domain.crt
COPY domain.key /etc/nginx/domain.key
registry.confの編集
※Githubのソースがアップデートされたようですが、現在下記のエラーが発生します。(2015/5/26)
nginx: [emerg] unknown directive "more_set_headers" in /etc/nginx/conf.d/registry.conf
こちらを解決するために、registry.conf
のmore_set_header
をコメントアウトし、下記のようにadd_header
に変更しましょう。
# The docker client expects this header from the /v2/ endpoint.
# more_set_headers 'Docker-Distribution-Api-Version: registry/2.0';
add_header 'Docker-Distribution-Api-Version:' 'registry/2.0' always;
Nginx設定ファイルの編集
下記をregistry.conf
に追記します。
server {...}
のすぐ下でOKです。
ssl on;
ssl_certificate /etc/nginx/domain.crt;
ssl_certificate_key /etc/nginx/domain.key;
ビルド
registry 1.0 イメージの取得
この例だとregistry 1.0
を併用しています。
併用の理由ですが、現行最新版のバージョン1.6よりも古いバージョンのdockerクライアントでは、registry 2.0
に対応しておらず、どちらの場合でも利用できるようにするためです。
(registry 2.0
からは、GitHubのリポジトリが今回クローンしているリポジトリに変更されました)
$ docker pull registry:0.9.1
ビルドディレクトリに移動
distribution/contrib/compose
に移動する。
ビルド実行
$ docker-compose build
実行
レジストリの立ち上げ
$ docker-compose up
hello-worldイメージをpushする
$ docker pull hello-world #DockerHubからpull
$ docker tag hello-world:latest localhost:5000/hello-world:latest #tagを付与する
$ docker push localhost:5000/hello-world:latest #Private Registryにpush
http://localhost:5000/v2/hello-world/tags/list にアクセスすると、JSONでpushした情報が返却されます。
Macの人は、Virtual Boxのポートフォワーディング設定を行っておくこと必要があるので注意して下さい。
hello-worldをpullする
確認のため先程のlocalhost:5000/hello-world:latest
イメージを消去した後、下記コマンドでpullする
$ docker run localhost:5000/hello-mine
S3をイメージ保存先に変更する
registry 2.0 の設定変更
distribution/cmd/registry/config.yml
中の
storage:
に下記の設定を追記し、filesystem
の設定を削除する
s3:
accesskey: awsaccesskey
secretkey: awssecretkey
region: ap-northeast-1
bucket: bucketname
encrypt: true
secure: true
v4auth: true
rootdirectory: /s3/object/name/prefix
※うまく走らなかったので、chunksizeの設定抜きました(2015/5/26)
ビルドディレクトリに移動
distribution/contrib/compose
に移動する。
ビルド実行
$ docker-compose build