Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command

UPDATE (March 2020, thanks @ic): I don't know the exact AMI version but yum install docker now works on the latest Amazon Linux 2. The instructions below may still be relevant depending on the vintage AMI you are using.

Amazon changed the install in Linux 2. One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/

Docker CE Install

sudo amazon-linux-extras install docker
sudo service docker start
sudo usermod -a -G docker ec2-user

Make docker auto-start

sudo chkconfig docker on

Because you always need it....

sudo yum install -y git

Reboot to verify it all loads fine on its own.

sudo reboot

docker-compose install

Copy the appropriate docker-compose binary from GitHub:

sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

NOTE: to get the latest version (thanks @spodnet): sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

Fix permissions after download:

sudo chmod +x /usr/local/bin/docker-compose

Verify success:

docker-compose version

@ajbazz

This comment has been minimized.

Copy link

ajbazz commented May 8, 2019

Excellent! Thanks for the instructions.

The only problem I had was running sudo reboot. I am logged on to my EC2 instance console using the AWS Systems Manager/Session Manager.
That command just hung and I had to terminate the instance. So I'm not sure if that was temporary issue or it isn't supported on Session Manager.

@rimiti

This comment has been minimized.

Copy link

rimiti commented May 11, 2019

Thanks @npearce, it works fine.

@laskarazhar-hiveup

This comment has been minimized.

Copy link

laskarazhar-hiveup commented May 17, 2019

Thanks @npearce, handy steps.

@johnycage

This comment has been minimized.

Copy link

johnycage commented May 23, 2019

Other guides on the web doesn't work. Yours is just perfect. Thanks.

@XaeroDegreaz

This comment has been minimized.

Copy link

XaeroDegreaz commented May 27, 2019

Thank you

@jvirico

This comment has been minimized.

Copy link

jvirico commented Jun 4, 2019

Easy, thanks!

@egroj97

This comment has been minimized.

Copy link

egroj97 commented Jun 6, 2019

Thanks! Worked like a charm

@pkaramol

This comment has been minimized.

Copy link

pkaramol commented Jun 7, 2019

I think the systemctl commands work fine on Amazon Linux 2 given that it has systemd.

systemctl enable --now docker should suffice.

@igorGevaerd

This comment has been minimized.

Copy link

igorGevaerd commented Jun 14, 2019

Works like a charm.
Thanks!

@matiasepalacios

This comment has been minimized.

Copy link

matiasepalacios commented Aug 22, 2019

you are the fucking master!

@btskloud

This comment has been minimized.

Copy link

btskloud commented Sep 9, 2019

Yes, this worked great!!

@msafder

This comment has been minimized.

Copy link

msafder commented Sep 10, 2019

still works!

@adisubektie

This comment has been minimized.

Copy link

adisubektie commented Sep 27, 2019

perfect code. thanks alots

@johnnyrich0617

This comment has been minimized.

Copy link

johnnyrich0617 commented Oct 23, 2019

Thank so much for this...you saved me hours!

@bek9

This comment has been minimized.

Copy link

bek9 commented Nov 11, 2019

👍👍

@bdurrani

This comment has been minimized.

Copy link

bdurrani commented Dec 18, 2019

if you don't want to hardcode the user when adding the name to the group, you can also do sudo usermod -aG docker $USER

@xtealer

This comment has been minimized.

Copy link

xtealer commented Dec 23, 2019

Ran into an issue when trying to run service docker start. Fixed it with this AWSDevs thread that says to install sudo yum install polkit

@kush199423

This comment has been minimized.

Copy link

kush199423 commented Feb 4, 2020

Thanks works awsom . thanks a ton .

@ic

This comment has been minimized.

Copy link

ic commented Mar 5, 2020

Thank you for the explanation.

It seems we can now use yum again to install Docker, simplifying the first step:

sudo yum install docker

just worked out of the box a few minutes ago.

@npearce

This comment has been minimized.

Copy link
Owner Author

npearce commented Mar 8, 2020

Thank you for the explanation.

It seems we can now use yum again to install Docker, simplifying the first step:

sudo yum install docker

just worked out of the box a few minutes ago.

Only took them a year... :)
Thanks for sharing this, @ic

@ic

This comment has been minimized.

Copy link

ic commented Mar 8, 2020

@npearce Thank you for the original tip. I guess it is still valid on old AMIs. Even a year will not change that :)

@MiKr13

This comment has been minimized.

Copy link

MiKr13 commented Mar 24, 2020

Hi please help, I am getting this error:

Error: Package: containerd.io-1.2.13-3.1.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74

When I am doing: amazon-linux-extras install docker

@ic

This comment has been minimized.

Copy link

ic commented Mar 25, 2020

When I am doing: amazon-linux-extras install docker

Would you have more context? The gist assumes a few things on the AMI, etc.

Also, yum should just work on recent/updated systems, now.

@pystocks

This comment has been minimized.

Copy link

pystocks commented Mar 25, 2020

When I am doing: amazon-linux-extras install docker

Would you have more context? The gist assumes a few things on the AMI, etc.

Also, yum should just work on recent/updated systems, now.

I'm getting the same error when trying to install docker.

sudo yum install amazon-linux-extras install docker

returns

Error: Package: containerd.io-1.2.13-3.1.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

@CarlosBalladares

This comment has been minimized.

Copy link

CarlosBalladares commented Mar 28, 2020

@psystocks

Any luck?

@pystocks

This comment has been minimized.

Copy link

pystocks commented Mar 29, 2020

@psystocks

Any luck?

@CarlosBalladares

Not sure what was wrong. However, I just launched a new ec2 instance and it worked.

@MiKr13

This comment has been minimized.

Copy link

MiKr13 commented Mar 29, 2020

@CarlosBalladares @pystock this approach of launching a new instance isn't even valid for me since I was already in a new lauched instance trying to setup docker.

@MiKr13

This comment has been minimized.

Copy link

MiKr13 commented Mar 29, 2020

@ic I just lauched a new Linux AMI v2 instance on AWS, it's a t3a Medium instance. I followed this tutorial to the teeth and did everything the same way said here but I was getting that error

Error: Package: containerd.io-1.2.13-3.1.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74 
@CarlosBalladares

This comment has been minimized.

Copy link

CarlosBalladares commented Mar 29, 2020

I switched from AMI to ubuntu.

@pystocks

This comment has been minimized.

Copy link

pystocks commented Mar 29, 2020

@MiKr13 On a new instance, did you try just doing a regular yum install docker? It worked for me.

@xmariopereira

This comment has been minimized.

Copy link

xmariopereira commented Apr 2, 2020

Error: Package: containerd.io-1.2.13-3.1.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74

Same problem here. it was working some days ago.

@MiKr13

This comment has been minimized.

Copy link

MiKr13 commented Apr 2, 2020

@pystocks I don't know if it's the VM issue or what but yes, after creating another new VM with Amazon AMI V2 and installing docker with just yum install docker worked.

@fawolfmann

This comment has been minimized.

Copy link

fawolfmann commented Apr 26, 2020

Thanks! it worked perfectly

@Spodnet

This comment has been minimized.

Copy link

Spodnet commented May 3, 2020

Use

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

to get latest version of docker-compose rather than a fixed version

@endangurura

This comment has been minimized.

Copy link

endangurura commented May 4, 2020

Thanks! worked like a charm

@npearce

This comment has been minimized.

Copy link
Owner Author

npearce commented May 5, 2020

Use

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

to get latest version of docker-compose rather than a fixed version

Nice one.

@jrobertomercadog

This comment has been minimized.

Copy link

jrobertomercadog commented May 9, 2020

Works like a charm! Thanks for sharing.

@dezren39

This comment has been minimized.

Copy link

dezren39 commented May 11, 2020

Thank you

@namnguyenbk

This comment has been minimized.

Copy link

namnguyenbk commented May 14, 2020

Thanks for your kind help. It worked very well

@shide1989

This comment has been minimized.

Copy link

shide1989 commented May 20, 2020

More than usefull ! thanks !

@Andrew-Chen-Wang

This comment has been minimized.

Copy link

Andrew-Chen-Wang commented Jun 10, 2020

On Amazon Linux 2, for those who are lazy (including me):

sudo amazon-linux-extras install -y docker && sudo service docker start && sudo usermod -a -G docker ec2-user && sudo chkconfig docker on && sudo yum install -y git && sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && docker-compose version && sudo reboot

And then just re-login.

Also, for those who are using OS X and have this weird " that is typed as some non-ASCII double quote, here's another one-liner for rsync-ing your code:

rsync -av -e "ssh -i ~/path/to/dev.pem" ./ ec2-user@your-ec2-dns:~/code

./ assumes you're in the directory you want to rsync. Otherwise, specify a path.

@jaedung

This comment has been minimized.

Copy link

jaedung commented Jun 10, 2020

To verify the command docker-compose version, I had to create a symbolic link using the command ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose.

@mobeigi

This comment has been minimized.

Copy link

mobeigi commented Jul 11, 2020

Thanks for the steps :D

@soufi

This comment has been minimized.

Copy link

soufi commented Jul 20, 2020

Excellent ! Thanks !

@rizzumd

This comment has been minimized.

Copy link

rizzumd commented Jul 27, 2020

Works great! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.