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
Answer from Prashanth Sams on Stack Overflow
🌐
nixCraft
cyberciti.biz › nixcraft › howto › amazon cloud computing › how to install docker on amazon linux 2
How to install Docker on Amazon Linux 2 - nixCraft
October 8, 2024 - Then run any one of the following sudo pip3 install docker-compose # with root access # OR # pip3 install --user docker-compose # without root access for security reasons ... wget https://github.com/docker/compose/releases/latest/download/d...
Discussions

How to install Docker on Amazon linux 2023? - Stack Overflow
I am trying to install docker engine on amazon linux 2023 using the docker ce repo with no luck. i tried to install Docker on amazon linux 2 using the "amazon-linux-extras" but its no lon... More on stackoverflow.com
🌐 stackoverflow.com
Docker installation fails on amazon linux 2 when following the official installation method
I know it doesn’t really answer your question, but AL2 goes end of life next year, is there a reason you would not use AL2023? More on reddit.com
🌐 r/aws
19
5
October 12, 2024
How do I install docker version 27.3.1 on Amazon Linux 2023?
Updated docker packages addressing ... Linux 2 (docker-20.10.25-1.amzn2.0.5 and docker-25.0.6-1.amzn2.0.1) and for Amazon Linux 2023 (docker-25.0.6-1amzn2023.0.1). AWS recommends that customers using docker upgrade to these or later versions. (CVE-2024-41110) ... $ cat /etc/os-release | grep PRETTY PRETTY_NAME="Amazon Linux 2023.6.20241121" $ dnf info docker Installed Packages Name ... More on repost.aws
🌐 repost.aws
5
0
November 27, 2024
Installing docker-compose on Amazon EC2 Linux 2. 9kb docker-compose file - Stack Overflow
First of all, let me state I'm not the most virtuous of Linux users, so bear with me... Below is a brief run-down of all the steps I took. Ultimately the question/issue is is that it seems impossib... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
gist.github.com › npearce › 6f3c7826c7499587f00957fee62f8ee9
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command · GitHub
One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/ sudo amazon-linux-extras install docker sudo service docker start sudo usermod -a -G docker ec2-user
🌐
Medium
swapnasagarpradhan.medium.com › how-to-install-docker-on-amazon-linux-2-8e5161ac5464
How to install Docker on Amazon Linux 2 | by Swapnasagar Pradhan | Medium
October 15, 2022 - How to install Docker on Amazon Linux 2 The procedure to install Docker on AMI 2 (Amazon Linux 2) Login into the remote AWS server using the ssh command or connect EC2 Instance Connect (browser-based …
🌐
Sebastien Taggart
sebastientaggart.com › posts › how to install docker on amazon linux 2
How to Install Docker on Amazon Linux 2 | D. Sébastien Taggart
November 4, 2025 - Keep in mind that Amazon Linux tends to ship with an older version of the Docker engine. At the time of this writing, the latest Docker version is 19.03, while Amazon’s package offers 18.09. This disparity could affect certain features or compatibility, so always check the version you need for your projects. If you’re looking to manage multi-container Docker applications, Docker Compose is your friend. You can install it using the following command:
🌐
DEV Community
dev.to › rodrigobruner › how-to-install-docker-on-amazon-linux-2-1na4
How to install Docker on Amazon Linux 2 - DEV Community
May 29, 2023 - How do I install docker and docker-compose on Amazon Linux 2 running on the EC2 or Lightsail cloud... Tagged with docker, aws.
Find elsewhere
🌐
Docker Hub
hub.docker.com › _ › amazonlinux
amazonlinux - Official Image | Docker Hub
Yes; in order to avoid any disruption to your existing applications and to facilitate migration to Amazon Linux 2023, AWS will provide regular security updates for Amazon Linux 2 and Amazon Linux 2018.03. Please refer to their FAQs for more information.
🌐
Untitled Publication
innosufiyan.hashnode.dev › installing-docker-on-amazon-linux-ec2-instance
Installing Docker on Amazon Linux EC2 Instance
January 23, 2025 - First, we need to update the existing ... To do this, run: ... Now that the packages are updated, we’ll install Docker using the Yum install command....
🌐
LinkedIn
linkedin.com › pulse › installing-docker-amazon-linux-2-fahd-mirza
Installing Docker on Amazon Linux 2
August 14, 2020 - I've installed Docker several times on AMZN2 without issues. Generally you only have to make sure you're using a compatible containerd (i.e. work around some weird YUM issues). ... Don’t have the app? Get it in the Microsoft Store. Open the app ... By clicking Continue, you agree to LinkedIn’s User Agreement, Privacy Policy, and Cookie Policy. ... What are the benefits and drawbacks of using snap, flatpak, or appimage for package management in Linux?
🌐
Reddit
reddit.com › r/aws › docker installation fails on amazon linux 2 when following the official installation method
r/aws on Reddit: Docker installation fails on amazon linux 2 when following the official installation method
October 12, 2024 -
  • I want to install docker 27.2.0 on amazon linux 2

  • I followed the guide as mentioned here

Steps

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

I am immediately running into this error

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
https://download.docker.com/linux/centos/2/x86_64/stable/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.


 One of the configured repositories failed (Docker CE Stable - x86_64),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=docker-ce-stable ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable docker-ce-stable
        or
            subscription-manager repos --disable=docker-ce-stable

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=docker-ce-stable.skip_if_unavailable=true

failure: repodata/repomd.xml from docker-ce-stable: [Errno 256] No more mirrors to try.
https://download.docker.com/linux/centos/2/x86_64/stable/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found

Anyone knows how to get docker running inside Amazon Linux 2 EC2 instance?

Just to clarify i am trying to run this inside EC2 user data script in case that matters

Top answer
1 of 5
4
Here is what has worked for me: ``` sudo dnf update -y # Remove old version sudo dnf remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine # Install dnf plugin sudo dnf -y install dnf-plugins-core # Add CentOS repository sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # Adjust release server version in the path as it will not match with Amazon Linux 2023 sudo sed -i 's/$releasever/9/g' /etc/yum.repos.d/docker-ce.repo # Install as usual sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # Enable the docker service sudo systemctl enable --now docker ```
2 of 5
1
`My EC2 VM currently has Docker version 25.0.5, build 5dc9bcc installed, but this version has a security flaw that has been patched in versions 27.1.1 and above.` Are you referring to CVE-2024-41110? Affected versions include `<= v25.0.5` and `<= v27.1.0` You can refer to Amazon Linux Security Center ALAS-2024-674 which mentions `AWS is aware of CVE-2024-41110, an issue affecting the Moby open source project, packaged in Amazon Linux as "docker". Docker is a component of several open source container management systems.` `Updated docker packages addressing the issue are available for Amazon Linux 2 (docker-20.10.25-1.amzn2.0.5 and docker-25.0.6-1.amzn2.0.1) and for Amazon Linux 2023 (docker-25.0.6-1amzn2023.0.1). AWS recommends that customers using docker upgrade to these or later versions. (CVE-2024-41110)` On my AL2023, docker 25.0.6 is installed ``` $ cat /etc/os-release | grep PRETTY PRETTY_NAME="Amazon Linux 2023.6.20241121" $ dnf info docker Installed Packages Name : docker Version : 25.0.6 Release : 1.amzn2023.0.2 Architecture : aarch64 Size : 150 M Source : docker-25.0.6-1.amzn2023.0.2.src.rpm Repository : @System From repo : amazonlinux Summary : Automates deployment of containerized applications URL : http://www.docker.com License : ASL 2.0 and MIT and BSD and MPLv2.0 and WTFPL Description : Docker is an open-source engine that automates the deployment of any : application as a lightweight, portable, self-sufficient container that will : run virtually anywhere. : : Docker containers can encapsulate any payload, and will run consistently on : and between virtually any server. The same container that a developer builds : and tests on a laptop will run at scale, in production*, on VMs, bare-metal : servers, OpenStack clusters, public instances, or combinations of the above. ```
Top answer
1 of 5
98

To get Docker running on the AWS AMI you should follow the steps below (these are all assuming you have ssh'd on to the EC2 instance).

  1. Update the packages on your instance

    [ec2-user ~]$ sudo yum update -y

  2. Install Docker

    [ec2-user ~]$ sudo yum install docker -y

  3. Start the Docker Service

    [ec2-user ~]$ sudo service docker start

  4. Add the ec2-user to the docker group so you can execute Docker commands without using sudo.

    [ec2-user ~]$ sudo usermod -a -G docker ec2-user

You should then be able to run all of the docker commands without requiring sudo. After running the 4th command I did need to logout and log back in for the change to take effect.

2 of 5
7

The hardest part to figure all of this out was the container-selinux requirement. Just find the latest version in http://mirror.centos.org/centos/7/extras/x86_64/Packages/ and install that first. In addition EC2 instances may not have a proper entropy generator so haveged may need to be installed.

The rest is taken from https://docs.docker.com/install/linux/docker-ce/centos/ with the addition of haveged and firewalld. All these have to be done as root so sudo appropriately.

yum install -q -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.42-1.gitad8f0f7.el7.noarch.rpm
yum install -q -y http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/h/haveged-1.9.1-1.el7.x86_64.rpm
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -q -y firewalld docker-ce
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --add-port=2377/tcp --permanent
firewall-cmd --add-port=2376/tcp --permanent
firewall-cmd --add-port=7946/tcp --permanent
firewall-cmd --add-port=7946/udp --permanent
firewall-cmd --add-port=4789/udp --permanent
firewall-cmd --zone=public --permanent --add-masquerade
firewall-cmd --reload
systemctl enable haveged
systemctl start haveged
systemctl enable docker
systemctl start docker
setenforce 1

Enable SELinux by modifying /etc/sysconfig/selinux to be

SELINUX=enforcing
SELINUXTYPE=targeted

Then reboot your instance by issuing shutdown -r now

Executing sudo docker version should yield as of the time of this posting...

Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24
 Built: Wed Mar 21 23:09:15 2018
 OS/Arch:       linux/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:      18.03.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   0520e24
  Built:        Wed Mar 21 23:13:03 2018
  OS/Arch:      linux/amd64
  Experimental: false
🌐
Floating Cloud
floatingcloud.io › home › how to install docker and compose on amazon linux 2
How to install Docker and Compose on Amazon Linux 2 - Floating Cloud
March 28, 2023 - Log in to your Amazon Linux 2 instance. Open a terminal and run the following command to update your system: ... Install the required packages: Docker, containerd, git, and screen, by running the following command: ... wget https://github.c...
🌐
GitHub
gist.github.com › thimslugga › 36019e15b2a47a48c495b661d18faa6d
Setup Docker on Amazon Linux 2023 · GitHub
sudo dnf install --allowerasing -y \ docker \ containerd \ runc \ container-selinux \ cni-plugins \ oci-add-hooks \ amazon-ecr-credential-helper \ udica
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-install-docker-on-amazon-linux
How to Install Docker on Amazon Linux - GeeksforGeeks
June 13, 2024 - Now run the command to update the Linux system. After updating the linux system run the command 'sudo yum install -y docker' to install the docker package into the Linux system.After the sucessful installation you can see the screen as shown below.
🌐
Medium
medium.com › @geeekfa › docker-and-docker-compose-on-aws-linux-2-9e90f79502db
Docker and Docker Compose on AWS Linux 2 | by GeeekFa | Medium
December 13, 2023 - ... Start by launching an AWS EC2 instance with the Amazon Linux 2 AMI. 3. Open a terminal and SSH to the AWS EC2 instance: ssh -i <YOUR_PRIVATE_KEY.pem> <YOUR_USER_NAME>@<THE_AWS_EC2_PUBLIC_DNS_ADDRESS> ... sudo yum install -y amazon-linux-extras sudo amazon-linux-extras install docker ...
🌐
DEV Community
dev.to › dasanirban834 › docker-installation-on-amazon-linux-2-or-amazon-linux-2023-5afa
Docker: Installation on Amazon Linux 2 or Amazon Linux 2023 - DEV Community
September 8, 2024 - Learn how to choose the best method for you to install Docker Engine. This client-server application is available on Linux, Mac, Windows, and as a static binary.