2015年6月30日火曜日

Oracle Linux 6.x とローカル Docker Registry。

Docker のコンテナイメージは、Docker Hub から入手することが多いと思います。
https://registry.hub.docker.com/

この Docker Hub となるサーバを構築することもできます。
Oracle Linux 7.x であれば public-yum リポジトリに docker-registry がありました。
[root@docker-reg ~]# yum info docker-registry
読み込んだプラグイン:security
利用可能なパッケージ
名前                : docker-registry
アーキテクチャ      : noarch
バージョン          : 0.6.8
リリース            : 8.el7
容量                : 124 k
リポジトリー        : ol7_addons
要約                : Registry server for Docker
URL                 : https://github.com/dotcloud/docker-registry
ライセンス          : ASL 2.0
説明                : Registry server for Docker (hosting/delivering of
                    : repositories and images).

しかし Oracle Linux 6.x 用の RPM は見あたらなかったので
Docker コンテナで起動してみようと思います。
https://docs.docker.com/registry/

今回は Oracle Linux 6.6 を使用しています。
docker-reg (IP アドレス: 192.168.1.6)という Linux で Docker Registry コンテナを起動します。
[root@docker-reg ~]# cat /etc/oracle-release
Oracle Linux Server release 6.6
[root@docker-reg ~]# uname -r
3.8.13-44.1.1.el6uek.x86_64
[root@docker-reg ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:a0:d2:e0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.6/24 brd 192.168.1.255 scope global eth0
    inet6 2408:210:a3c8:7000:250:56ff:fea0:d2e0/64 scope global dynamic
       valid_lft 13100sec preferred_lft 11300sec
    inet6 fe80::250:56ff:fea0:d2e0/64 scope link
       valid_lft forever preferred_lft forever

Docker Registry の用意。

今回は、すでに Docker はインストールずみで、サービスも起動してあります。
[root@docker-reg ~]# rpm -q docker
docker-1.6.1-1.0.1.el6.x86_64
[root@docker-reg ~]# docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
Pool Name: docker-252:0-132135-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 305.7 MB
Data Space Total: 107.4 GB
Data Space Available: 11.12 GB
Metadata Space Used: 729.1 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.89-RHEL6 (2014-09-01)
Execution Driver: native-0.2
Kernel Version: 3.8.13-44.1.1.el6uek.x86_64
Operating System: 
CPUs: 1
Total Memory: 994.7 MiB
Name: docker-reg
ID: VCXE:B4DX:QHXC:BVO4:735K:T5ZU:XWV5:QF2Z:C5ER:OFJD:KLPD:Y2RC

オフィシャルの Registry コンテナは、
docker search で探すと、OFFICIAL が [OK] になっています。
※Search 結果を絞り込むため、stars の数値を大きくしています。
[root@docker-reg ~]# docker search --stars=300 registry
NAME       DESCRIPTION                     STARS     OFFICIAL   AUTOMATED
registry   Containerized docker registry   306       [OK]

イメージをダウンロードします。
[root@docker-reg ~]# docker pull registry
latest: Pulling from registry
428b411c28f0: Pull complete
435050075b3f: Pull complete
9fd3c8c9af32: Pull complete
6d4946999d4f: Pull complete
cf73ddbcb12b: Pull complete
6c1042649795: Pull complete
bf5c9d5c651c: Pull complete
d907e837e8d2: Pull complete
e7a5ac6474fc: Pull complete
056a477d8cde: Pull complete
88f8b53e7469: Pull complete
17e0da3fda2f: Pull complete
efc16b071fbf: Pull complete
70d8f0edf5c9: Already exists
registry:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:39fde46ab5b2413979060d47fa8fcf3f598290e5312d5be78d8539ede545e731
Status: Downloaded newer image for registry:latest

ダウンロードしたイメージが登録されました。
[root@docker-reg ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry            latest              70d8f0edf5c9        12 days ago         413.9 MB

コンテナを起動します。
これで Registry が使用できるようになりました。
[root@docker-reg ~]# docker run -d -p 5000:5000 --name reg01 registry
6b94ccbe4622271727d986815f3d7b7fd8a37f93c4e044a8d94fcd550e9382f3
[root@docker-reg ~]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
6b94ccbe4622        registry:latest     "docker-registry"   17 seconds ago      Up 14 seconds       0.0.0.0:5000->5000/tcp   reg01

Docker ホストでの /etc/sysconfig/docker ファイル編集。

今回の Registry に Docker ホストからアクセスするには、
/etc/sysconfig/docker ファイルに、下記の設定を追記しておきます。
証明書を作成していないので・・・
[root@docker-host01 ~]# cat /etc/sysconfig/docker
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d

#other_args=""
other_args="--insecure-registry 192.168.1.6:5000"

ファイル編集後、docker を再起動します。
[root@docker-host01 ~]# service docker restart
docker を停止中:                                           [  OK  ]
Starting docker:                                           [  OK  ]

ちなみに、この設定をしないと、pull / push のときに下記のようなエラーになります。
[root@docker-host01 ~]# docker pull 192.168.1.6:5000/oraclelinux:6.6
FATA[0004] Error response from daemon: v1 ping attempt failed with error: Get https://192.168.1.6:5000/v1/_ping: EOF. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.1.6:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/192.168.1.6:5000/ca.crt

Docker ホストから Registry へのコンテナ イメージ登録 (push)。

Docker ホスト(別の Oracle Linux 6.6)から Registry にイメージ登録してみます。
まず、普通の Docker Hub Registry から
Oracle Linux 6.6 のコンテナイメージをダウンロードします。
[root@docker-host01 ~]# docker pull oraclelinux:6.6
6.6: Pulling from oraclelinux
8c3e49cb06dc: Pull complete
13d222df5522: Pull complete
f1ae29046210: Already exists
oraclelinux:6.6: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:c4692d51336c5eafba69f5f4bac838b2e3e7e1c7eacff9fad72bea7c6e03d42f
Status: Downloaded newer image for oraclelinux:6.6

Docker ホストに、コンテナイメージ「oraclelinux:6.6」が登録されました。
[root@docker-host01 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
oraclelinux         6.6                 f1ae29046210        13 days ago         157.7 MB

イメージの新しいタグをつけて、「192.168.1.6:5000/gowatana/ol6」として
Docker Registry に登録(push)してみます。
[root@docker-host01 ~]# docker tag oraclelinux:6.6 192.168.1.6:5000/gowatana/ol6:u6
[root@docker-host01 ~]# docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
oraclelinux                     6.6                 f1ae29046210        13 days ago         157.7 MB
192.168.1.6:5000/gowatana/ol6   u6                  f1ae29046210        13 days ago         157.7 MB

[root@docker-host01 ~]# docker push 192.168.1.6:5000/gowatana/ol6:u6
The push refers to a repository [192.168.1.6:5000/gowatana/ol6] (len: 1)
Sending image list
Pushing repository 192.168.1.6:5000/gowatana/ol6 (1 tags)
8c3e49cb06dc: Image successfully pushed
13d222df5522: Image successfully pushed
f1ae29046210: Image successfully pushed
Pushing tag for rev [f1ae29046210] on {http://192.168.1.6:5000/v1/repositories/gowatana/ol6/tags/u6}
Registry にイメージが登録されました。
[root@docker-host01 ~]# docker search 192.168.1.6:5000/gowatana
NAME           DESCRIPTION   STARS     OFFICIAL   AUTOMATED
gowatana/ol6                 0

Registry からのコンテナ イメージ取得 (pull)。

いったん、Docker ホストに登録ずみのイメージを削除してみます。
[root@docker-host01 ~]# docker rmi oraclelinux:6.6
Untagged: oraclelinux:6.6
[root@docker-host01 ~]# docker rmi 192.168.1.6:5000/gowatana/ol6:u6
Untagged: 192.168.1.6:5000/gowatana/ol6:u6
Deleted: f1ae290462108ef7928eb2e1fb07a7940fd8b9220686de29f9912d978b638f55
Deleted: 13d222df5522e324f3eb25475c530d01a3e0f4b760e670f7cf7e86744e4d93c3
Deleted: 8c3e49cb06dc5b36240627eca5238665ce373d96f41e28947920828dfe434381

Docker ホストのイメージはなくなりました。
[root@docker-host01 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

Registry からコンテナをダウンロード(pull)してみます。
[root@docker-host01 ~]# docker pull 192.168.1.6:5000/gowatana/ol6:u6
Pulling repository 192.168.1.6:5000/gowatana/ol6
f1ae29046210: Download complete
8c3e49cb06dc: Download complete
13d222df5522: Download complete
Status: Downloaded newer image for 192.168.1.6:5000/gowatana/ol6:u6
[root@docker-host01 ~]# docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
192.168.1.6:5000/gowatana/ol6   u6                  f1ae29046210        13 days ago         157.7 MB

コンテナを起動してみます。
[root@docker-host01 ~]# docker run -it 192.168.1.6:5000/gowatana/ol6:u6 /bin/bash
[root@2fa309b23c8f /]#

以上、Oracle Linux 上で Docker Registory を用意してみる話でした。

0 件のコメント:

コメントを投稿