投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2018年8月24日金曜日

【Linux CentOS 7】Dockerをyumでインストールする手順と簡単な動作テスト【Docker-ce 18.06.1.ce】


□システムのバージョンの表示

CentOS 7 minimalを導入して、updateを行ったものである。

# uname -a
Linux localhost.localdomain 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux


■ Dockerリポジトリの導入

○ 必要なパッケージの追加

yum install yum-utils device-mapper-persistent-data lvm2

Installed:
  device-mapper-persistent-data.x86_64 0:0.7.3-3.el7                         
  lvm2.x86_64 7:2.02.177-4.el7                                               
  yum-utils.noarch 0:1.1.31-46.el7_5                                         
Dependency Installed:
  device-mapper-event.x86_64 7:1.02.146-4.el7                                 
  device-mapper-event-libs.x86_64 7:1.02.146-4.el7                           
  libaio.x86_64 0:0.3.109-13.el7                                             
  libxml2-python.x86_64 0:2.9.1-6.el7_2.3                                     
  lvm2-libs.x86_64 7:2.02.177-4.el7                                           
  python-chardet.noarch 0:2.2.1-1.el7_1                                       
  python-kitchen.noarch 0:1.1.1-5.el7                                         
Complete!

○ Dockerリポジトリ(ステーブル)の設定

(エッジ、テスト版リポジトリの導入については参考サイトへ)

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
読み込んだプラグイン:fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

○ 利用可能なDockerのバージョンの一覧

# yum list docker-ce --showduplicates | sort -r
利用可能なパッケージ
読み込んだプラグイン:fastestmirror
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Loading mirror speeds from cached hostfile
 * updates: ftp.riken.jp
 * extras: ftp.riken.jp
 * base: ftp.riken.jp

○インストールされるバージョンの確認

# yum info docker-ce                                          
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
利用可能なパッケージ
名前                : docker-ce
アーキテクチャー    : x86_64
バージョン          : 18.06.1.ce
リリース            : 3.el7
容量                : 41 M
リポジトリー        : docker-ce-stable/x86_64
要約                : The open-source application container engine
URL                 : https://www.docker.com
ライセンス          : ASL 2.0
説明                : Docker is an open source project to build, ship and run
                    : any application as a lightweight container.
                    :
                    : Docker containers are both hardware-agnostic and
                    : platform-agnostic. This means they can run anywhere, from
                    : your laptop to the largest cloud compute instance and
                    : everything in between - and they don't require you to use
                    : a particular language, framework or packaging system. That
                    : makes them great building blocks for deploying and scaling
                    : web apps, databases, and backend services without
                    : depending on a particular stack or provider.

○インストール

# yum install docker-ce
インストール:
  docker-ce.x86_64 0:18.06.1.ce-3.el7                                         
依存性関連をインストールしました:
  audit-libs-python.x86_64 0:2.8.1-3.el7_5.1                                 
  checkpolicy.x86_64 0:2.5-6.el7                                             
  container-selinux.noarch 2:2.68-1.el7                                       
  libcgroup.x86_64 0:0.41-15.el7                                             
  libsemanage-python.x86_64 0:2.5-11.el7                                     
  libtool-ltdl.x86_64 0:2.4.2-22.el7_3                                       
  policycoreutils-python.x86_64 0:2.5-22.el7                                 
  python-IPy.noarch 0:0.75-6.el7                                             
  setools-libs.x86_64 0:3.3.8-2.el7                                           
完了しました!


■動作テスト

○Dockerエンジンの起動

# systemctl start docker

もし、エラーが出て起動しない場合は、システムを再起動すると良かった


○サンプルイメージを取得してコンテナを動作

Docker Hubがホストするhello-worldというイメージからコンテナを作成し、
コンテナを動作させようとしている。
イメージがローカルにまだなければ、Docker Hubから自動的に取得される。
(動作手順は、下記、1〜4に記載されている。)

# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/
For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

■動作テスト 2

また、さらに上記のコメントには、Ubuntuイメージから作成したコンテナを動作させて、
試しにそのbashを呼び出してみよと教えてくれているので、その通りやってみた。

コンテナ実行後、下記のように、コンテナ内のbashが表示するプロンプトに含まれる文字列は、
この場合(公式 Ubuntuイメージ)ではコンテナのIDと同一ものだった。

# docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
c64513b74145: Pull complete 
01b8b12bad90: Pull complete 
c5d85cf7a05f: Pull complete 
b6b268720157: Pull complete 
e12192999ff1: Pull complete 
Digest: sha256:aade50db36e1ed96716662cfe748789e154c213a711931c66746c42ce34aa296
Status: Downloaded newer image for ubuntu:latest
root@e0f42e71cf38:/#

root@e0f42e71cf38:/# uname -a
Linux e0f42e71cf38 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
root@e0f42e71cf38:/# free -m
              total        used        free      shared  buff/cache   available
Mem:           1999         194        1256           8         548        1642
Swap:          1906           0        1906
root@e0f42e71cf38:/# pwd
/
root@e0f42e71cf38:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
root@e0f42e71cf38:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          16G  1.4G   15G   9% /
tmpfs            64M     0   64M   0% /dev
tmpfs          1000M     0 1000M   0% /sys/fs/cgroup
/dev/vda5        16G  1.4G   15G   9% /etc/hosts
shm              64M     0   64M   0% /dev/shm
tmpfs          1000M     0 1000M   0% /proc/acpi
tmpfs          1000M     0 1000M   0% /proc/scsi
tmpfs          1000M     0 1000M   0% /sys/firmware
root@e0f42e71cf38:/#


○コンテナ動作中のホストのディレクトリの状態

# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/vda5         16G  1.4G   15G    9% /
devtmpfs         990M     0  990M    0% /dev
tmpfs           1000M     0 1000M    0% /dev/shm
tmpfs           1000M  8.7M  992M    1% /run
tmpfs           1000M     0 1000M    0% /sys/fs/cgroup
/dev/vda2        2.0G   33M  2.0G    2% /tmp
/dev/vda1        473M  139M  335M   30% /boot
tmpfs            200M     0  200M    0% /run/user/0
overlay           16G  1.4G   15G    9% /var/lib/docker/overlay2/fc8817131b983e1c3c9984e0802c9a2b1fea1ee4fa9fdffa0d76dc9577265f37/merged
shm               64M     0   64M    0% /var/lib/docker/containers/e0f42e71cf384b40de5d0bc9323e3b65cf01d4bc06418b94c4ad680b5dc53be9/mounts/shm

○動作中のコンテナ一覧

動作中のコンテナのIDなどを確認できる。

# docker stats
CONTAINER ID        NAME                 CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
e0f42e71cf38        optimistic_almeida   0.00%               400KiB / 1.953GiB   0.02%               648B / 0B           0B / 0B             1
○IDで指定してコンテナを終了

上記で調べたIDを用いた。

# docker stop e0f42e71cf38
e0f42e71cf38
○イメージの差分であるオーバーレイヤーとしてマウントされたディレクトリの内容を表示

.bash_historyファイルが更新されたことがわかる。

# ls /var/lib/docker/overlay2/fc8817131b983e1c3c9984e0802c9a2b1fea1ee4fa9fdffa0d76dc9577265f37/*/* -al
/var/lib/docker/overlay2/fc8817131b983e1c3c9984e0802c9a2b1fea1ee4fa9fdffa0d76dc9577265f37/diff/root:
合計 4
drwx------ 2 root root 27  8月 23 01:23 .
drwxr-xr-x 3 root root 18  8月 22 13:37 ..
-rw------- 1 root root 72  8月 23 01:23 .bash_history
/var/lib/docker/overlay2/fc8817131b983e1c3c9984e0802c9a2b1fea1ee4fa9fdffa0d76dc9577265f37/work/work:
合計 0
d--------- 2 root root  6  8月 23 01:23 .
drwx------ 3 root root 18  8月 22 13:37 ..

○ Ubuntuコンテナを動作させる前のメモリの使用量と動作後の使用量の比較

<前>
              total        used        free      shared  buff/cache   available
Mem:           2.0G        148M        1.3G        8.6M        478M        1.6G
Swap:          1.9G          0B        1.9G

<動作中>
              total        used        free      shared  buff/cache   available
Mem:           1999         168        1257           8         573        1643
Swap:          1906           0        1906



<参考>
・Get Docker CE for CentOS
< https://docs.docker.com/install/linux/docker-ce/centos/ > 2018年8月23日

・Gracefully Stopping Docker Containers
< https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/ > 2018年8月23日

・Why docker has ability to run different linux distribution? [closed]
< https://stackoverflow.com/questions/25444099/why-docker-has-ability-to-run-different-linux-distribution?noredirect=1&lq=1 > 2018年8月23日

投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad