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
🌐
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.
Discussions

How do I install docker version 27.3.1 on Amazon Linux 2023?
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. More on repost.aws
🌐 repost.aws
5
0
November 27, 2024
How to run AmazonLinux 2023 on a local Docker host?
For example, these containers don't have common Linux/Unix tools like "ps", so normal system administration processes may fail. If I run the container without adding a process like httpd, the container starts up and then dies. I need the container to start up and stay up. FROM amazonlinux:latest RUN yum install httpd -y RUN systemctl start httpd RUN systemctl enable httpd ENTRYPOINT ["/bin/bash"] ... [+] Building 2.6s (6/7) docker... More on repost.aws
🌐 repost.aws
4
0
June 26, 2024
php - Docker with Amazon Linux - Stack Overflow
I had the same goal of testing instances in development environment and initially I thought it should be as easy as docker run amazonlinux:2 -it. More on stackoverflow.com
🌐 stackoverflow.com
Not able to install latest Docker engine in Amazon Linux 2 on EC2
Is it possible to install latest Docker engine in Amazon Linux 2 on EC2? As per this doc, https://docs.docker.com/engine/release-notes/, Docker 24.0.2 is the latest version. ``` $ sudo amazon-lin... More on repost.aws
🌐 repost.aws
1
0
June 6, 2023
🌐
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 - This page explains how to install Docker and docker-compose on Amazon Linux 2 to containerized applications on AMI on EC2/Lightsail cloud.
Find elsewhere
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. ```
🌐
ECR Public Gallery
gallery.ecr.aws › amazonlinux › amazonlinux
Amazon ECR Public Gallery - Amazon Linux/amazonlinux
Similar to the Amazon Linux images for AWS EC2 and on-premises use, Amazon Linux container images will get ongoing updates from Amazon in the form of security updates, bug fix updates, and other enhancements.
Top answer
1 of 4
17

I had the same goal of testing instances in development environment and initially I thought it should be as easy as docker run amazonlinux:2 -it. But I was so wrong and it took me almost one full day to get it to work!

Funny thing is when you google "amazonlinux Docker" it's often people trying to install "Docker in amazonlinux", but here we want to install "amazonlinux in Docker"!

We also want to install Docker in that amazonlinux, so basically "Docker in amazonlinux in Docker" which is "Docker in Docker" eventually! ;D*

My findings:

  • Amazonlinux in Docker (created via FROM amazonlinux:2) is so bare and empty that it doesn't even have basic stuffs like sudo or passwd.) New AWS EC2 instances do.
  • In order to have your serviced properly working (to start any daemon, including Docker Daemon), you need to have /usr/sbin/init be there (via yum install initscripts and actually called. However, the meat you want to play with need your shell to start from /bin/bash.
  • You are running a Docker within a Docker. That needs to be priviledged from the host in your docker run via --priviledged.
  • You need to share the /sys/fs/cgroup from your host machine (it can be read-only) for it to be able to properly initialize docker daemon.

My solution:

1) To fulfill the first two issues above, your Dockerfile can be:

CopyFROM amazonlinux:2

RUN yum update -y && yum install -y initscripts;

CMD ["/usr/sbin/init"]

2) Build an image from it, e.g. docker build . -t ax1

3) Then, to address the latter two issues above, run a detached (running in background) container from it, priviledged, with a shared volume to your /sys/fs/cgroup. e.g.

docker run --name ac11 -d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro ax1

4) Finally you can bash into it using docker exec -it ac11 bash

5) Now, it's very close to a new EC2 instance. (Yet, missing sudo, actual ec2-user and other stuffs that we skipped in our Dockerfile to keep this solution simple.)

Anyway, now you can install docker as instructed by AWS Docs. That is, once you are in the container, do:

Copyamazon-linux-extras install -y docker;

and then restart the docker service once:

Copyservice docker restart;

Now, docker ps should be working!

2 of 4
4

Docker containers stops when they don't have a process to run. Add an entrypoint to your Dockerfile to keep the machine running.

You could do a sleep infinity or sleep 99999 if you don't really have any process to run.

CopyFROM amazonlinux:2017.03

RUN yum update -y

CMD [“sleep”, “infinity”]
🌐
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 - docker login # amd64 docker buildx build --platform linux/amd64 -t <your_docker_hub_username>/api-flask:latest-amd64 --push . # arm64 docker buildx build --platform linux/arm64 -t <your_docker_hub_username>/api-flask:latest-arm64 --push .
🌐
Amazon Web Services
aws.amazon.com › products › compute › amazon linux 2
Amazon Linux 2
2 weeks ago - Amazon Linux 2 is a Linux operating system from AWS. It provides a security-focused, stable, and high-performance execution environment to develop and run cloud applications. Amazon Linux 2 is provided at no additional charge.
🌐
LinkedIn
linkedin.com › pulse › docker-aws-amazon-linux-2-instance-steven-aranibar
Docker On AWS Amazon Linux 2 Instance
February 8, 2021 - TL;DR If you choose to install docker on either Amazon Linux 1 or Amazon Linux 2 AMI's - please follow the official aws docs for installation. Do not follow the official docker website tutorial, which will fail, set up repos not needed on the Amazon Linux 1/2 instances, and then interfere with the A
🌐
Bun
bun.com › docs › installation
Installation - Bun
... Bun requires Windows 10 version 1809 or later.For support and discussion, join the #windows channel on the Discord. ... Bun provides a Docker image that supports both Linux x64 and arm64.
🌐
Kubernetes
kubernetes.io › docs › tasks › tools › install-kubectl-linux
Install and Set Up kubectl on Linux | Kubernetes
May 15, 2025 - If you are on Linux and using Homebrew package manager, kubectl is available for installation.
🌐
Docker
docker.com › pricing | docker
Pricing | Docker
April 11, 2025 - Docker licensing is always free for personal use. But what if your team or business wants to use Docker? Compare our pricing options and features.
🌐
CIS Center for Internet Security
cisecurity.org › cis benchmarks®
CIS Benchmarks®
Amazon Elastic Kubernetes Service (EKS) (2.0.0) Kubernetes (2.0.1) Azure Kubernetes Service (AKS) (2.0.0) Red Hat OpenShift Container Platform (1.9.0) Redhat OpenShift Virtual Machine Extension (1.0.0) To further explore this Benchmark, click here. If you want to tailor the security recommendations of this Benchmark, you can do so using a CIS SecureSuite Membership · Download The Benchmark · Available versions include: Linux Mint 22 (1.0.0) To further explore this Benchmark, click here.