How to install docker on Amazon Linux2
Asked Answered
P

9

27

I wanna create docker image for Amazon ECR. but yum can't find it in my Amazon Linux2.

[root@*** ~]# yum install -y docker
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
No package docker available.
Error: Nothing to do

Next, I tried to use amazon-linux-extras.

but amazon-linux-extras is not found, too.

[root@*** ~]# amazon-linux-extras install docker -y
-bash: amazon-linux-extras: command not found
[root@*** ~]# find / -name 'amazon-linux-extras'
[root@*** ~]$ cat /proc/version
Linux version 4.14.77-81.59.amzn2.x86_64 (mockbuild@ip-10-0-1-59) (gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)) #1 SMP Mon Nov 12 21:32:48 UTC 2018

How can I install amazon-linux-extras or create docker image?

Paulino answered 25/12, 2018 at 2:4 Comment(1)
Thank you. For aws cli official docker image, amazon-linux-extras install docker -y worked.Cocteau
P
20

So sorry, it was my misunderstanding. My OS is Redhat Linux. I get to install docker by

yum-config-manager --enable rhui-REGION-rhel-server-extras
yum -y install docker 
systemctl start docker
systemctl enable docker
docker version
Paulino answered 25/12, 2018 at 6:22 Comment(1)
I had to sudo yum -y install dockerPeregrine
R
40

Install Docker

sudo yum update -y
sudo yum -y install docker

Start Docker

sudo service docker start

Access Docker commands in ec2-user user

sudo usermod -a -G docker ec2-user
sudo chmod 666 /var/run/docker.sock
docker version
Rida answered 10/5, 2020 at 7:17 Comment(5)
this is correct but the chmod 666 is bad, just log off and connect again after adding the groupMachismo
Dont forget to sudo systemctl enable docker to make docker start on rebootPrepotent
@Machismo Please let me know what is recommended chmod for docker.sock ?Extrasystole
what is usermod -a -G docker ec2-user doing?Degraded
Thanks for your answer. If you could provide a comment on what the chmod 666 command is doing and why it is needed that would be particularly helpful.Degraded
P
20

So sorry, it was my misunderstanding. My OS is Redhat Linux. I get to install docker by

yum-config-manager --enable rhui-REGION-rhel-server-extras
yum -y install docker 
systemctl start docker
systemctl enable docker
docker version
Paulino answered 25/12, 2018 at 6:22 Comment(1)
I had to sudo yum -y install dockerPeregrine
C
9

Make sure you have amazon-linux-extras installed

[root@ip-20-0-0-112 ~]# which amazon-linux-extras
/usr/bin/amazon-linux-extras

If not install amazon-linux-extras using yum

yum -y install amazon-linux-extras

Then install docker using

amazon-linux-extras install docker
Centesimal answered 25/12, 2018 at 3:41 Comment(6)
Thanks, Prasad. I got no amazon-linux-extras via which and No package amazon-linux-extras available. via yum.Paulino
try: sudo yum -y install epel-releasePrime
@PedroLuz it does not help. The output is amzn-main | 2.1 kB 00:00:00 amzn-updates | 2.5 kB 00:00:00 Package epel-release-6-8.9.amzn1.noarch already installed and latest version Nothing to doMyrmidon
@boldnik I get the same thing. Did you find any solution?Kolkhoz
@Kolkhoz I decided to drop this idea using any custom Linux distribution by Amazon developers because it has too small community and has unpredictable and too poor documentation (if any at all), so I can only suggest to use a more common Linux distro with well known packages repository (as in /etc/apt/sources.list) and much more transparent configuration.Myrmidon
How to install a specific version of docker? (Given that for reproducibility, one should always install specific versions.)Tetrapterous
P
6

I'm on amazon linux (RHEL 7.2) - ami-035b3c7efe6d061d5,

cat /proc/version
Linux version 4.14.123-86.109.amzn1.x86_64 (mockbuild@koji-pdx-corp-builder-64004) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC)) #1 SMP Mon Jun 10 19:44:53 UTC 2019

Following script works without having to install amazon-linux-extras install

sudo yum -y install docker 
sudo service docker start
sudo chmod 666 /var/run/docker.sock

I had to fix permission issue. Also described here How to fix docker: Got permission denied issue

Then I can check containers,

[ec2-user@ip-30-0-0-196 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
Peregrine answered 26/7, 2019 at 2:33 Comment(1)
This response is misleading. The requester is asking how to install amazon-linux-extras.Dethrone
I
5

You can use the below script to install docker inside Amazon Linux 2 Instance. Also, you can mention the below script in the ec2 user data section so at the time of server bootstrap docker will be installed automatically.

#!/bin/bash
sudo yum update -y
sudo yum -y install docker
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo chmod 666 /var/run/docker.sock
Itemized answered 24/4, 2022 at 13:59 Comment(2)
does this start docker again when you reboot the instance?Sundaysundberg
Yes, this will do that. You can verify.Itemized
C
3

For the Amazon Linux AMI, access to the Extra Packages for Enterprise Linux (EPEL) repository is configured, but it is not enabled by default.

To install amazon-linux-extras, verify connection to the internet from within the instance then check the instance's OS:

cat /etc/os-release

If the OS is amazon linux version 2 run

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Or run sudo yum-config-manager --enable epel

To use the EPEL repository. You can now install available packages... e.g. sudo amazon-linux-extras install docker

see aws documentation for more details.

Crambo answered 8/8, 2019 at 2:52 Comment(0)
B
2

Amazon Linux 2 comes with amazon-linux-extras installed. If you think that you are running Amazon Linux 2, and amazon-linux-extras is not on the path of the ec2-user, you might be running an older version of Amazon Linux. Run this command:

grep PRETTY_NAME /etc/os-release 

It should output

PRETTY_NAME="Amazon Linux 2"

If you don't see that, go back to the ec2 console and drill-down into the details of the instance. Clicking on the AMI should reveal that it corresponds to an older version of Amazon Linux. Some AWS facilities, notably CDK, currently default to Amazon Linux instead of Amazon Linux 2 when creating new instances.

Begun answered 9/2, 2021 at 23:4 Comment(2)
run "sudo yum update" after creating the instance and it will be updated to "Amazon Linux 2"Zip
@GrigoryIlizirov, I was doing that via User Data and found that updating did not give me a number of facilities that I get with AL2, like Instance Connect and amazon-linux-extras.Begun
R
2

I came across this question when trying to set up a docker image, based on Amazon Linux 2. What I didn't find in the current answers is that the docker needs to be enabled in amazon-linux-extras before installing. Dockerfile commands that worked for me:

RUN yum install -y amazon-linux-extras
RUN amazon-linux-extras enable docker
RUN yum install -y docker
Rutherford answered 4/2, 2022 at 7:36 Comment(0)
V
0

You can do this with EC2 UserData so docker is available when the instance is first started:

yum update -y

amazon-linux-extras install docker

# Start service, give perms to default user, and persist service
service docker start
usermod -a -G docker ec2-user
chkconfig docker on

Valval answered 9/1 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.