m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

Dockerのインストール2(docker pull、httpd起動)

きんきょー

虫歯、痛風となんか病気に襲われまくりw
健康には気をつけるが甘いものの誘惑には負けてしまう。

リポジトリを取得

レポジトリともいうかもしれない
前回serviceが動かなかったのはバージョンが古いやつと思うので別のバージョンものを使用


Docker Hub Registry - Repositories of Docker Images

f:id:m_shige1979:20141021205719j:plain

centos6を取得

pull
# docker pull centos:centos6
Pulling repository centos
68edf809afe7: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6             68edf809afe7        2 weeks ago         212.7 MB
centos              latest              87e5b6b3ccc1        2 weeks ago         224 MB
#
centos6のタグで起動
# docker run -i -p 8080:80 -t centos:centos6 /bin/bash
bash-4.1# yum install -y httpd
# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.11 for ServerName
                                                           [  OK  ]
bash-4.1#
index.html
<html>
        <body>
                <h1>docker httpd test</h1>
        </body>
</html>
ポート変換している8080へアクセス

f:id:m_shige1979:20141021211213j:plain
※VMPlayerのIPでアクセス可能、80番も使用していないのならアクセス可能

イメージを保存する

exitにより抜ける
# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                        PORTS               NAMES
b117b9f09934        centos:centos6      /bin/bash              4 minutes ago       Exited (0) 25 seconds ago                         high_goldstine
c9f8fac42537        centos:centos6      /bin/bash              12 minutes ago      Exited (0) 5 minutes ago                          drunk_turing
8c0067f7fab1        centos:centos6      /bin/bash              13 minutes ago      Exited (0) 12 minutes ago                         naughty_kowalevski
7558163e275d        centos:latest       /bin/bash              13 minutes ago      Exited (0) 13 minutes ago                         agitated_almeida
eba39d949a26        centos:latest       /bin/bash              26 minutes ago      Exited (0) 23 minutes ago                         goofy_hopper
d98daeb84295        centos:latest       /bin/bash              32 minutes ago      Exited (127) 31 minutes ago                       ecstatic_poincare
54d8e7bce662        centos:latest       /bin/bash              32 minutes ago      Exited (127) 32 minutes ago                       lonely_perlman
178fcdc2dc5c        centos:latest       /bin/bash              3 hours ago         Exited (127) 3 hours ago                          stupefied_curie
14368a507ed9        centos:latest       /bin/bash              3 hours ago         Exited (0) 3 hours ago                            goofy_thompson
9dcb82062e2d        centos:latest       /bin/bash              3 hours ago         Exited (0) 3 hours ago                            elegant_wozniak
9f11ea5dab50        centos:latest       /bin/echo 'Hello Wor   4 hours ago         Exited (0) 4 hours ago                            goofy_poincare
#

※一番上のものが最新なのでIDを取得する

commitを行う
# docker commit b117b9f09934 sample1/centos65
beb2549038371b11e298eac50e50d4c42d746cc2fc7ba8dd54c3b49b95ad2da2
#

※完成

イメージがあることを確認
# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sample1/centos65    latest              beb254903837        21 seconds ago      305.7 MB
centos              centos6             68edf809afe7        2 weeks ago         212.7 MB
centos              latest              87e5b6b3ccc1        2 weeks ago         224 MB
#

※これで前回の続きの設定を利用できる

削除

停止しているコンテナは「docker ps -a」で確認できるので
# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                        PORTS               NAMES
b117b9f09934        centos:centos6      /bin/bash              11 minutes ago      Exited (0) 6 minutes ago                          high_goldstine
c9f8fac42537        centos:centos6      /bin/bash              18 minutes ago      Exited (0) 11 minutes ago                         drunk_turing
8c0067f7fab1        centos:centos6      /bin/bash              19 minutes ago      Exited (0) 18 minutes ago                         naughty_kowalevski
7558163e275d        centos:latest       /bin/bash              19 minutes ago      Exited (0) 19 minutes ago                         agitated_almeida
eba39d949a26        centos:latest       /bin/bash              32 minutes ago      Exited (0) 29 minutes ago                         goofy_hopper
d98daeb84295        centos:latest       /bin/bash              38 minutes ago      Exited (127) 37 minutes ago                       ecstatic_poincare
54d8e7bce662        centos:latest       /bin/bash              39 minutes ago      Exited (127) 38 minutes ago                       lonely_perlman
178fcdc2dc5c        centos:latest       /bin/bash              3 hours ago         Exited (127) 3 hours ago                          stupefied_curie
14368a507ed9        centos:latest       /bin/bash              3 hours ago         Exited (0) 3 hours ago                            goofy_thompson
9dcb82062e2d        centos:latest       /bin/bash              4 hours ago         Exited (0) 4 hours ago                            elegant_wozniak
9f11ea5dab50        centos:latest       /bin/echo 'Hello Wor   4 hours ago         Exited (0) 4 hours ago                            goofy_poincare
#
#
# docker rm `docker ps -a -q`
b117b9f09934
c9f8fac42537
8c0067f7fab1
7558163e275d
eba39d949a26
d98daeb84295
54d8e7bce662
178fcdc2dc5c
14368a507ed9
9dcb82062e2d
9f11ea5dab50
# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
#
イメージは「rmi」で削除する
# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sample1/centos65    latest              beb254903837        8 minutes ago       305.7 MB
centos              centos6             68edf809afe7        2 weeks ago         212.7 MB
centos              latest              87e5b6b3ccc1        2 weeks ago         224 MB
#
# docker rmi beb254903837
Untagged: sample1/centos65:latest
Deleted: beb2549038371b11e298eac50e50d4c42d746cc2fc7ba8dd54c3b49b95ad2da2
#
# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6             68edf809afe7        2 weeks ago         212.7 MB
centos              latest              87e5b6b3ccc1        2 weeks ago         224 MB
#
#

所感

dockerの場合はイメージとコンテナの制御で使いすてが簡単に見える感じ。
VMPlayerやvagrantなどで1つの仮想環境を用意してその中にタグ付けしたイメージを複数用意できるので間違った場合など、入れ替えが簡単にできるイメージ。

他の人の環境にイメージを映せるがどうかがちょっと分からないけど…
Dockerfileとか使えばいいのかも…

参考


MacにDockerをインストールして使ってみました :: Co-mit Engineers Blog