kuroの覚え書き

96の個人的覚え書き

CentOS7にDocker

これまでデスクトップサーバで深層学習環境をUbuntuに構築するこころみをしてきたが、やはり時代はDockerだな、ということでUbuntuにDockerをインストールしたりまではやっていたのだが、なんというかやはりサーバとしてはUbuntuって凄く使い難い。なんか専用のモニタのくっついたデスクトップマシンでないとリモートではどうも使いにくいのだ。
てことで使いなれたCentOSにまた舞い戻ってきた。なんかここ行ったり来たりしてる。
ちなみにCentOS7は最小構成でインストールし、groupinstallで "GNOME Desktop"をいれ、念の為linuxbrewをインストールしただけの最低限の準備で、あとはDocker上で全てどうにかする予定。現在CentOS7にlinuxbrewをインストールする手順は
k-kuro.hatenadiary.jp
ここで書いた通りの手順がやはり必要。

[kkuro@E5800-T110f-E ~]$ su
Password: 
[root@E5800-T110f-E kkuro]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * epel: ftp.jaist.ac.jp
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
Resolving Dependencies
--> Running transaction check

〜〜中略〜〜

Complete!
[root@E5800-T110f-E kkuro]# yum upgrade
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * epel: ftp.jaist.ac.jp
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
No packages marked for update
[root@E5800-T110f-E kkuro]# yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * epel: ftp.jaist.ac.jp
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Package device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 already installed and latest version
Package 7:lvm2-2.02.187-6.el7_9.5.x86_64 already installed and latest version
Nothing to do
[root@E5800-T110f-E kkuro]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
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
[root@E5800-T110f-E kkuro]# yum install -y docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * epel: ftp.jaist.ac.jp
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
docker-ce-stable                                         | 3.5 kB     00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo                |   55 B   00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                |  62 kB   00:00     
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.6-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.4.6-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:20.10.7-3.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.7-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.7-3.el7 will be installed
--> Processing Dependency: docker-scan-plugin(x86-64) for package: 1:docker-ce-cli-20.10.7-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package docker-ce-rootless-extras.x86_64 0:20.10.7-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.7-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.7-3.el7.x86_64
---> Package docker-scan-plugin.x86_64 0:0.8.0-3.el7 will be installed
--> Running transaction check
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch   Version                   Repository        Size
================================================================================
Installing:
 containerd.io          x86_64 1.4.6-3.1.el7             docker-ce-stable  34 M
 docker-ce              x86_64 3:20.10.7-3.el7           docker-ce-stable  27 M
 docker-ce-cli          x86_64 1:20.10.7-3.el7           docker-ce-stable  33 M
Installing for dependencies:
 container-selinux      noarch 2:2.119.2-1.911c772.el7_8 extras            40 k
 docker-ce-rootless-extras
                        x86_64 20.10.7-3.el7             docker-ce-stable 9.2 M
 docker-scan-plugin     x86_64 0.8.0-3.el7               docker-ce-stable 4.2 M
 fuse-overlayfs         x86_64 0.7.2-6.el7_8             extras            54 k
 fuse3-libs             x86_64 3.6.1-4.el7               extras            82 k
 slirp4netns            x86_64 0.4.3-4.el7_8             extras            81 k

Transaction Summary
================================================================================
Install  3 Packages (+6 Dependent packages)

Total download size: 107 M
Installed size: 438 M
Downloading packages:
(1/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rp |  40 kB   00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.4.6-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for containerd.io-1.4.6-3.1.el7.x86_64.rpm is not installed
(2/9): containerd.io-1.4.6-3.1.el7.x86_64.rpm              |  34 MB   00:01     
(3/9): docker-ce-20.10.7-3.el7.x86_64.rpm                  |  27 MB   00:01     
(4/9): docker-ce-rootless-extras-20.10.7-3.el7.x86_64.rpm  | 9.2 MB   00:00     
(5/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm             |  54 kB   00:00     
(6/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm                   |  82 kB   00:00     
(7/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                |  81 kB   00:00     
(8/9): docker-scan-plugin-0.8.0-3.el7.x86_64.rpm           | 4.2 MB   00:00     
(9/9): docker-ce-cli-20.10.7-3.el7.x86_64.rpm              |  33 MB   00:01     
--------------------------------------------------------------------------------
Total                                               38 MB/s | 107 MB  00:02     
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch           1/9 
  Installing : containerd.io-1.4.6-3.1.el7.x86_64                           2/9 
  Installing : 1:docker-ce-cli-20.10.7-3.el7.x86_64                         3/9 
  Installing : docker-scan-plugin-0.8.0-3.el7.x86_64                        4/9 
  Installing : slirp4netns-0.4.3-4.el7_8.x86_64                             5/9 
  Installing : fuse3-libs-3.6.1-4.el7.x86_64                                6/9 
  Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64                          7/9 
  Installing : docker-ce-rootless-extras-20.10.7-3.el7.x86_64               8/9 
  Installing : 3:docker-ce-20.10.7-3.el7.x86_64                             9/9 
  Verifying  : containerd.io-1.4.6-3.1.el7.x86_64                           1/9 
  Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                2/9 
  Verifying  : docker-scan-plugin-0.8.0-3.el7.x86_64                        3/9 
  Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                             4/9 
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch           5/9 
  Verifying  : 3:docker-ce-20.10.7-3.el7.x86_64                             6/9 
  Verifying  : 1:docker-ce-cli-20.10.7-3.el7.x86_64                         7/9 
  Verifying  : docker-ce-rootless-extras-20.10.7-3.el7.x86_64               8/9 
  Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                          9/9 

Installed:
  containerd.io.x86_64 0:1.4.6-3.1.el7     docker-ce.x86_64 3:20.10.7-3.el7    
  docker-ce-cli.x86_64 1:20.10.7-3.el7    

Dependency Installed:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8                            
  docker-ce-rootless-extras.x86_64 0:20.10.7-3.el7                              
  docker-scan-plugin.x86_64 0:0.8.0-3.el7                                       
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8                                         
  fuse3-libs.x86_64 0:3.6.1-4.el7                                               
  slirp4netns.x86_64 0:0.4.3-4.el7_8                                            

Complete!
[root@E5800-T110f-E kkuro]# systemctl start docker
[root@E5800-T110f-E kkuro]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@E5800-T110f-E kkuro]# docker --version
Docker version 20.10.7, build f0df350
[root@E5800-T110f-E kkuro]# docker version
Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        f0df350
 Built:             Wed Jun  2 11:58:10 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:56:35 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@E5800-T110f-E kkuro]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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/get-started/

これで使えるようになった。

Dockerの参考図書購入。ちょっと初心者向け過ぎかもしれない。Linuxを日常使いしている向きにはかなり初歩的なところからの解説が面倒くさく感じるかもしれない。基本Windowsユーザ(またはUnix的に使用していないMacユーザ)を対象としている。
一応Linuxベースの解説もあるが基本UbuntuCentOS/RHEL系の解説はないので、そのへんはネットで探す必要があった。
【CentOS7】Dockerインストールと起動 | インフラエンジニアの技術LOG
こちらのブログを参考にさせていただいた。