Skip to content

Instantly share code, notes, and snippets.

@npearce
Last active March 24, 2024 04:39
Star You must be signed in to star a gist
Save npearce/6f3c7826c7499587f00957fee62f8ee9 to your computer and use it in GitHub Desktop.
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

@caohunan
Copy link

caohunan commented Aug 4, 2021

still works!

@michaelact
Copy link

Thanks!!

@zanio
Copy link

zanio commented Aug 13, 2021

Still working. Thanks!

@SPONGE-JL
Copy link

Perfect guide! Thank you :)

@evantlee
Copy link

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.

Confirming this. I had to do the same - and it's actually on the docker install instructions as well! Thanks for the helpful guide!

@axlfire1
Copy link

Excellent thanks

@alex-mishe
Copy link

thanks !

@spellingb
Copy link

superb. ty kind internet stranger

@FutureGadget
Copy link

This still works like a charm. TY!

@dzmitrykliapkou
Copy link

Be careful with this part now:

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

Docker-compose v2.0.0 has been released and they decided to change x86_64 to amd64 in the filename for the release. So as a result this link with $(uname -m) does not work anymore

@DevJulianSalas
Copy link

Thanks!

@Spunkie
Copy link

Spunkie commented Oct 7, 2021

Docker-compose v2.0.0 has been released and they decided to change x86_64 to amd64 in the filename for the release. So as a result this link with $(uname -m) does not work anymore

Looks like this was resolved quickly with a v2.0.1 release.


Also with the release of docker-compose v2 the official repo now includes arm64 builds. 🎉

@rakeshhegishte
Copy link

Thanks a lot. it worked for me

@ppshein
Copy link

ppshein commented Oct 22, 2021

ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

that's sweet.

@Chinweoke18
Copy link

@ozbillwang thanks a lot, solved it for me

@hscale
Copy link

hscale commented Nov 8, 2021

Should check PATH for run Docker-composer:

[root@ip-172-30-xx-xx bin]# PATH=/usr/local/bin:$PATH
[root@ip-172-30-xx-xx bin]# echo $PATH
/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

@tranvanthuc
Copy link

Thank you so much. It's worked!

@timogoosen
Copy link

The docker-compose part you can skip and just do:

sudo pip3 install docker-compose

You can do this right after installing docker, then do a reboot, then docker-compose should work fine.
Thanks for sharing this gist.
Was very helpful!

@eit
Copy link

eit commented Feb 17, 2022

use pip3 also works. thanks

@4RSIM3R
Copy link

4RSIM3R commented Feb 21, 2022

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

@Ucinorn
Copy link

Ucinorn commented Mar 1, 2022

For those who get all the way down here: the following userdata script works great for me on a basic Amazon Linux ARM EC2 instance:

#!/bin/bash
yum update
yum -y install docker
service docker start
usermod -a -G docker ec2-user
chkconfig docker on
pip3 install docker-compose
reboot

Note userdata always runs as root so no need to use sudo

After its finished initialising run this to see the output of the userscript to ensure it all ran as expected and for debugging:

sudo cat /var/log/cloud-init-output.log

@victorsferreira
Copy link

Guys in case you followed Docker instructions first you need to delete the repo before continuing:
sudo rm /etc/yum.repos.d/docker-ce.repo

@olen2006
Copy link

olen2006 commented Jul 6, 2022

delete the repo before continuing

provide link ? Never had to do it.

@olen2006
Copy link

olen2006 commented Jul 6, 2022

The docker-compose part you can skip and just do:

sudo pip3 install docker-compose

You can do this right after installing docker, then do a reboot, then docker-compose should work fine. Thanks for sharing this gist. Was very helpful!

depending on the version of distribution most likely you'll install an old version of docker-compose (1.29 vs 2.6.1)

@pkazi
Copy link

pkazi commented Jul 26, 2022

For me, uname -s returned Linux , but the download URL has linux, so converted to lowercase and updated curl to -

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m) -o /usr/bin/docker-compose && sudo chmod 755 /usr/bin/docker-compose && docker-compose --version

@ortizfelipe
Copy link

Thanks

@mmansour
Copy link

Works great. Thank you!

@Ahmed-Hodhod
Copy link

Thanks, it worked also on the AWS cloud shell...

@amitkumar-2
Copy link

thank you bro.....

@GDalonso
Copy link

Thank you

@shashankChndkr
Copy link

Thanks!

@younsl
Copy link

younsl commented Oct 21, 2022

Thank you bro, it works well!

@vlad8x8
Copy link

vlad8x8 commented Nov 1, 2022

just pulled amazonlinux:2

sh-4.2# service docker start
sh: service: command not found
sh-4.2# sudo service docker start
sh: sudo: command not found

@hotyes
Copy link

hotyes commented Nov 2, 2022

$ sudo usermod -a -G docker ec2-user
$ id ec2-user
# Reload a Linux user's group assignments to docker w/o logout
$ newgrp docker

@btskloud
Copy link

btskloud commented Nov 3, 2022 via email

@JaydotMurf
Copy link

Awesome!

@Alzavio
Copy link

Alzavio commented Nov 25, 2022

If this doesn't work for you for whatever reason, add it to PATH

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

@vlad8x8
Copy link

vlad8x8 commented Nov 25, 2022

be sure to restart your machine.

restart after what? right after I started it?
it can't find even sudo

@btskloud
Copy link

be sure to restart your machine.

restart after what? right after I started it? it can't find even sudo

You must have signed in as a non-sudoer

@btskloud
Copy link

be sure to restart your machine.

restart after what? right after I started it? it can't find even sudo

You must have signed in as a non-sudoer

Looking at your thread, you don’t have to start docker.. I will install it on Amazon Linux when I have extra time and reply with the steps.

@nietzscheson
Copy link

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

Add sudo for the permissions:

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

@marceloagoston
Copy link

works great!! THANKS A LOT!

@ramdassbhanage
Copy link

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

@omarelweshy
Copy link

For me, uname -s returned Linux , but the download URL has linux, so converted to lowercase and updated curl to -

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m) -o /usr/bin/docker-compose && sudo chmod 755 /usr/bin/docker-compose && docker-compose --version

THANKS!!!

@sikyeong
Copy link

@omarelweshy oh thanks a lot
that is for me, uname -s returned Linux, too.

@vincenthsh
Copy link

vincenthsh commented Mar 3, 2023

for compose v2
https://docs.docker.com/compose/install/linux/#install-the-plugin-manually

DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
# install for all users
# DOCKER_CONFIG=/usr/local/lib/docker
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

@Showrin
Copy link

Showrin commented Mar 8, 2023

Thank you.

@fefogarcia
Copy link

This saved me, thank you

@Geczy
Copy link

Geczy commented Apr 27, 2023

@vincenthsh 's solution worked for me as sudo

@MarwenAouiti
Copy link

MarwenAouiti commented May 29, 2023

wget https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)
sudo mv docker-compose-$(uname -s)-$(uname -m) /usr/local/bin/docker-compose
sudo chmod -v +x /usr/local/bin/docker-compose

@sahilsheikh-dev
Copy link

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

Note:
For me, uname -s returned Linux, but the download URL has linux so please replace it.
Also, uname -m returned x86_64 so replace that as well

Example:
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

@AustinGilkison
Copy link

Had an issue around the permissions command.
sudo usermod -a -G docker ec2-user

permission denied while trying to connect to the Docker daemon socket at .....

This seemed to be the fix:
sudo usermod -aG docker $USER

@OlliKantola
Copy link

Works like a charm. Thank you.

@itbrunoms
Copy link

The best anwser!!

@ShamalMuneer007
Copy link

THANK YOU!!!!

@kevindai007
Copy link

Thanks a lot, but for this command
sudo amazon-linux-extras install docker
i believe it should change to
sudo yum install docker

@316usman
Copy link

316usman commented Jan 8, 2024

Thanks docker-compose works great

@jonassteinberg1
Copy link

@tuancuongth88
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment