LoginSignup
10
9

More than 5 years have passed since last update.

Scientific LinuxのDockerイメージを作成する

Last updated at Posted at 2014-06-14

Docker Indexに公式に提供されている、Scientific Linuxのベースイメージがなかったので、自分で作ってみました。

成果物はこちら。

対象のVMを作成する

まず、Scientific Linux 6.5のDocker用ベースイメージを作成したい場合、
Scientific Linux 6.5のVMを作成します。

作り方はなんでもいいですが、Packerを使って作成する手順をまとめたのがこちらです。

以降の作業はこのVMの中で行います。

Dockerのインストール

まず、ベースイメージを作るためにDocekrをインストールします。

yumにEPELリポジトリを追加

sudo rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo yum -y update

もう、EPELリポジトリ以外はアップデート済みの場合は、
sudo yum -y update epel-releaseでもいいです。

Dockerのインストール

Dockerのインストールは普通にyumで行うだけ。簡単!

sudo yum -y install docker-io

Dockerベースイメージの作成

febootstrapというツールを使って作成します。
(詳しく知らないけど、debootstrapみたいなもの??)

作成用のシェルスクリプトを書きます。
名前は適当にsl65.shとかにしました。

#!/bin/bash

MIRROR_URL="http://ftp.riken.jp/Linux/scientific/6.5/x86_64/os/"
MIRROR_URL_UPDATES="http://ftp.riken.jp/Linux/scientific/6.5/x86_64/updates/security/"

yum install -y febootstrap xz

febootstrap -i bash -i coreutils -i tar -i bzip2 -i gzip -i vim-minimal -i wget -i patch -i diffutils -i iproute -i yum scientific scientific65  $MIRROR_URL -u $MIRROR_URL_UPDATES
touch scientific65/etc/resolv.conf
touch scientific65/sbin/init

tar --numeric-owner -Jcpf scientific-65.tar.xz -C scientific65 .

あとは、これを実行するだけ。

sudo ./sl65.sh

動作確認

シェルスクリプトを実行すると次のようなファイルが出来てます。

[vagrant@localhost ~]$ ls -l
total 51960
-rw-rw-r--  1 vagrant vagrant 53195204 Jun  1 15:10 scientific-65.tar.xz
dr-xr-xr-x 21 root    root        4096 Jun  1 15:07 scientific65
-rwxr-xr-x  1 vagrant vagrant      595 Jun  1 15:06 sl65.sh

こいつを、dockerにインポートします。

まず、dockerを起動。

sudo service docker start

次に、インポート。
リポジトリをlocal/scientificにして、tagを6.5にしました。

cat scientific-65.tar.xz | sudo docker import - local/scientific:6.5

imageを確認。

[vagrant@localhost ~]$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
local/scientific    6.5                 ad81296d21b0        13 minutes ago      309.6 MB

docker runしてみます。

[vagrant@localhost ~]$ sudo docker run local/scientific:6.5 cat /etc/system-release
Scientific Linux release 6.5 (Carbon)

よさそう。

Docker Indexにpushする

コマンドメモしか保存していなかったので、
ここから先はScientific Linux 6.4で実行ログを収集しました。

まず、実行している(いた)コンテナ一覧をみます。

[vagrant@localhost ~]$ sudo docker ps -a
CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS                      PORTS               NAMES
a266aa1f5c10        local/scientific:6.4   cat /etc/system-rele   37 minutes ago      Exited (0) 37 minutes ago                       determined_feynman

このコンテナをコミットします。
- a266aa1f5c10psで確認したCONTAINER ID
- ringo/scientificはDocker Indexで作成した自分のリポジトリ
- :の後ろにタグ

[vagrant@localhost ~]$ sudo docker commit a266aa1f5c10 ringo/scientific:6.4
0bdd7adac72c6d381e0fe56320252ffbfd39f1a965964115c598f2153fd7a9a8

ringo/scientificができました。

[vagrant@localhost ~]$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ringo/scientific    6.4                 0bdd7adac72c        10 seconds ago      308.9 MB
local/scientific    6.4                 c5cb7eb15e7e        38 minutes ago      308.9 MB

Push しましょう!!

[vagrant@localhost ~]$ sudo docker push ringo/scientific
The push refers to a repository [ringo/scientific] (len: 1)
Sending image list

Please login prior to push:
Username: ringo
Password:
Email:
Login Succeeded
The push refers to a repository [ringo/scientific] (len: 1)
Sending image list
Pushing repository ringo/scientific (1 tags)
c5cb7eb15e7e: Image successfully pushed
0bdd7adac72c: Image successfully pushed
Pushing tag for rev [0bdd7adac72c] on {https://registry-1.docker.io/v1/repositories/ringo/scientific/tags/6.4}

ベースイメージを使ってみる

まず、pullします。

[vagrant@localhost ~]$ sudo docker pull ringo/scientific
Pulling repository ringo/scientific
0bdd7adac72c: Download complete
1a2eb0bba51b: Download complete
c5cb7eb15e7e: Download complete
ae0b1be0b6ae: Download complete
[vagrant@localhost ~]$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ringo/scientific    6.4                 0bdd7adac72c        About an hour ago   308.9 MB
ringo/scientific    6.5                 1a2eb0bba51b        10 days ago         322.8 MB

つぎに、runします。

[vagrant@localhost ~]$ sudo docker run -i -t ringo/scientific:6.5 cat /etc/system-release
Scientific Linux release 6.5 (Carbon)

動いたー。

最後に

Scientific Linuxのベースイメージはringo/scientificにおいてあります。

また、ベースイメージを作成するのに利用した、スクリプトはgithub.com/ringohub/docker-base-imageにおいてあります。
よかったら、参考にどうぞ。

おわり!

参考

10
9
0

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
10
9