Amazon Linux2にDockerをインストール(container-selinuxエラーからの復帰)

備忘録

#yumでのインストールに失敗
公式の記述通りにインストールを実行
[Get Docker Engine - Community for CentOS](https://docs.docker.com/install/linux/docker-ce/centos/)
※そもそもAmazon LinuxにインストールしたいのにCentOSのページを参照していたことが間違い

```
[root@ip-192-168-0-1 ~]# yum makecache fast
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                 | 2.4 kB  00:00:00     
amzn2extra-docker                                                          | 1.3 kB  00:00:00     
Metadata Cache Created
[root@ip-192-168-0-1 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@ip-192-168-0-1 ~]# yum makecache fast
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                 | 2.4 kB  00:00:00     
amzn2extra-docker                                                          | 1.3 kB  00:00:00     
docker-ce-stable                                                           | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/x86_64/primary_db                                  |  37 kB  00:00:00     
(2/2): docker-ce-stable/x86_64/updateinfo                                  |   55 B  00:00:00     
Metadata Cache Created
[root@ip-192-168-0-1 ~]# sudo yum install docker-ce
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:19.03.5-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.5-3.el7.x86_
64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-19.03.5-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-19.03.5-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-19.03.5-3.el7.x86_64
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.10-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.10-3.2.el7.x
86_64
---> Package docker-ce.x86_64 3:19.03.5-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.5-3.el7.x86_
64
---> Package docker-ce-cli.x86_64 1:19.03.5-3.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-21.amzn2 will be installed
--> Finished Dependency Resolution
Error: Package: 3:docker-ce-19.03.5-3.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
Error: Package: containerd.io-1.2.10-3.2.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
```

#Amazon公式ページにて解決策を発見したが
[Amazon ECS における Docker の基本](https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/docker-basics.html)

同じエラーが発生

```
[root@ip-192-168-0-1 ~]# amazon-linux-extras install docker
Installing docker
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker docker-ce-stable
14 metadata files removed
6 sqlite files removed
0 metadata files removed
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                 | 2.4 kB  00:00:00     
amzn2extra-docker                                                          | 1.3 kB  00:00:00     
docker-ce-stable                                                           | 3.5 kB  00:00:00     
(1/6): amzn2-core/2/x86_64/updateinfo                                      | 184 kB  00:00:00     
(2/6): amzn2-core/2/x86_64/group_gz                                        | 2.5 kB  00:00:00     
(3/6): docker-ce-stable/x86_64/updateinfo                                  |   55 B  00:00:00     
(4/6): amzn2extra-docker/2/x86_64/primary_db                               |  59 kB  00:00:00     
(5/6): docker-ce-stable/x86_64/primary_db                                  |  37 kB  00:00:00     
(6/6): amzn2-core/2/x86_64/primary_db                                      |  36 MB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:18.09.9ce-2.amzn2 will be installed
--> Processing Dependency: runc = 1.0.0 for package: docker-18.09.9ce-2.amzn2.x86_64
--> Processing Dependency: containerd = 1.2.6 for package: docker-18.09.9ce-2.amzn2.x86_64
--> Processing Dependency: pigz for package: docker-18.09.9ce-2.amzn2.x86_64
--> Processing Dependency: libcgroup for package: docker-18.09.9ce-2.amzn2.x86_64
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.10-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.10-3.2.el7.x
86_64
---> Package libcgroup.x86_64 0:0.41-21.amzn2 will be installed
---> Package pigz.x86_64 0:2.3.4-1.amzn2.0.1 will be installed
--> Finished Dependency Resolution
Error: Package: containerd.io-1.2.10-3.2.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
Installation failed. Check that you have permissions to install.
```

#解決

最初に入れたdocker-ce.repoが原因で、そちらを参照していることが判明したため削除して再度インストール。



```
[root@ip-192-168-0-1 ~]# cd /etc/yum.repos.d/
[root@ip-192-168-0-1 ~]# yum.repos.d]# ls
amzn2-core.repo  amzn2-extras.repo  docker-ce.repo
[root@ip-192-168-0-1 ~]# yum.repos.d]# rm docker-ce.repo 
rm: remove regular file ‘docker-ce.repo’? y
[root@ip-192-168-0-1 ~]# yum.repos.d]# ls
amzn2-core.repo  amzn2-extras.repo
[root@ip-192-168-0-1 ~]# amazon-linux-extras install docker
Installing docker
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker
9 metadata files removed
4 sqlite files removed
0 metadata files removed
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                 | 2.4 kB  00:00:00     
amzn2extra-docker                                                          | 1.3 kB  00:00:00     
(1/4): amzn2-core/2/x86_64/group_gz                                        | 2.5 kB  00:00:00     
(2/4): amzn2-core/2/x86_64/updateinfo                                      | 184 kB  00:00:00     
(3/4): amzn2extra-docker/2/x86_64/primary_db                               |  59 kB  00:00:00     
(4/4): amzn2-core/2/x86_64/primary_db                                      |  36 MB  00:00:00     
~~~~~~~~省略~~~~~~~~
Installed:
  docker.x86_64 0:18.09.9ce-2.amzn2                                                               

Dependency Installed:
  containerd.x86_64 0:1.2.6-1.amzn2       libcgroup.x86_64 0:0.41-21.amzn2                       
  pigz.x86_64 0:2.3.4-1.amzn2.0.1         runc.x86_64 0:1.0.0-0.1.20190510.git2b18fe1.amzn2      

Complete!
```

無事完了しました。