Wednesday, August 12, 2020

Installing Docker on Amazon Linux 2

Installing docker on Amazon Linux 2 is full of surprises which are not easy to deal with. I just wanted to test something within a container environment, so spun up a new EC2 instance from the following AMI:

Amazon Linux 2 AMI (HVM), SSD Volume Type - ami-0ded330691a314693 (64-bit x86) / ami-0c3a4ad3dbe082a72 (64-bit Arm)

After this Linux instance came up, I just did yum update to get all the latest stuff:

 sudo yum update

All good so far.
Then I installed/checked yum-utils and grabbed the docker repo, and all good there:

[ec2-user@testf ~]$ sudo yum install -y yum-utils
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Package yum-utils-1.1.31-46.amzn2.0.1.noarch already installed and latest version
Nothing to do

[ec2-user@testf ~]$ sudo yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
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


Now, it's time to install docker:

[ec2-user@testf ~]$ sudo yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                               | 3.7 kB  00:00:00
docker-ce-stable                                                                                                         | 3.5 kB  00:00:00
(1/2): docker-ce-stable/x86_64/primary_db                                                                                |  45 kB  00:00:00
(2/2): docker-ce-stable/x86_64/updateinfo                                                                                |   55 B  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.13-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.13-3.2.el7.x86_64
---> Package docker-ce.x86_64 3:19.03.12-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.12-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-19.03.12-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:19.03.12-3.el7 will be installed
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.13-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.13-3.2.el7.x86_64
---> Package docker-ce.x86_64 3:19.03.12-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.12-3.el7.x86_64
---> Package libcgroup.x86_64 0:0.41-21.amzn2 will be installed
--> Finished Dependency Resolution
Error: Package: containerd.io-1.2.13-3.2.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
Error: Package: 3:docker-ce-19.03.12-3.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


and it failed. 

So googled the error Requires: container-selinux and every stackoverflow post and blogs say to download the new rpm from some centos or similar mirror but it simply doesn't work, no matter how hard you try. 

Here is the ultimate best solution which enabled me to get docker installed on Amazon Linux 2 on this EC2 server:

sudo rm /etc/yum.repos.d/docker-ce.repo

sudo amazon-linux-extras install docker

sudo service docker start

[ec2-user@~]$ docker --version

Docker version 19.03.6-ce, build 369ce74


That's it. I hope that helps.

No comments: