いつの間にか registry 2.0 になっていましたので 過去の記事 を2.0で書き直し。
環境
- Amazon Linux (ami-383c1956)
- Docker version 1.9.1, build a34a1d5/1.9.1
-
su
,sudo
は省略してます
registryを起動する
registry自体がdocker imageで提供されています。
↓はregistryにpushしたデータを -v `pwd`/data:/var/lib/registry
optionでホスト側にマウントしてます。
$ docker run -d -p 5000:5000 --name registry \
-v `pwd`/data:/var/lib/registry \
registry:2
使い方
基本は Docker Hub と同じ。イメージ名の前にURLとPORT <your.server.address>:<port>/
を付けます。
取得 (pull):
$ docker pull <your.server.address>:<port>/namespace/yourimage:tag
保存 (push):
$ docker tag namespace/yourimage:tag <your.server.address>:<port>/namespace/yourimage:tag
$ docker push <your.server.address>:<port>/namespace/yourimage:tag
実際に試してみる
Docker Hub から centos
imageをpullしてregistryにpushしてみます。
簡単の為、registryもdockerホストもlocalhostで動かします
$ docker pull centos
registryに centos
imageをpushする。 (tag付けが必要)
$ docker tag centos localhost:5000/centos
$ docker push localhost:5000/centos
registryからpullしてみる。
$ docker pull localhost:5000/centos
HTTP (insecure) で通信する
dockerはregistryに対し標準でSSL通信をするので、SSLの設定をしていない場合エラーになります。
Using default tag: latest
Error response from daemon: unable to ping registry endpoint https://<your.server.address>:<port>/v0/
v2 ping attempt failed with error: Get https://<your.server.address>:<port>/v2/: tls: oversized record received with length 20527
v1 ping attempt failed with error: Get https://<your.server.address>:<port>/v1/_ping: tls: oversized record received with length 20527
docker起動時のOPTIONに --insecure-registry <your.server.address>:<port>
を追加して、HTTPで通信させます。
# Additional startup options for the Docker daemon, for example:
# OPTIONS="--ip-forward=true --iptables=true"
# By default we limit the number of open files per container
OPTIONS="--default-ulimit nofile=1024:4096 --insecure-registry <your.server.address>:<port>"
dockerを再起動する。
$ service docker restart