How to Install Docker and Docker Compose on Amazon Linux 2023

If you have recently migrated to Amazon Linux 2023 (AL2023), you might have noticed that some of your old setup scripts for Amazon Linux 2 don’t behave as expected. AL2023 is a modern, Fedora-based OS that minimizes the default package footprint to improve security and performance. It uses dnf instead of yum. By the end of this guide, you will have a production-ready Docker setup on your EC2 instance.

Prerequisites

Before we install Docker, ensure your environment is ready

  • An AWS EC2 instance running Amazon Linux 2023.
  • SSH access to the server.

Step 1: Update Your System

Update your Linux with the latest repository updates by running the command below.

sudo dnf update -y

Step 2: Install Docker on Amazon Linux 2023

The advantage of AL2023 is that it includes Docker in its default repository, unlike some other distributions, where you need to add a repository first.

sudo dnf install -y docker

Step 3: Start and Enable the Docker Service

Once Docker is installed, start the Docker service to make sure it runs in the background.

sudo systemctl start docker
sudo systemctl enable docker

To ensure that Docker is installed correctly and is running, execute the following:

sudo systemctl status docker

This command should display the Docker version, indicating a successful installation.

Step 4: Allow Running Docker Without Sudo (Optional but Recommended)

Developers hate typing sudo for every Docker command. So run the below command to have ec2-user have permission to run Docker without sudo.

sudo usermod -aG docker ec2-user
newgrp docker

Step 5: How to Install Docker Compose on Amazon Linux 2023

docker-compose (standalone) is often preferred over the plugin by legacy users, but show the modern binary installation method to ensure they get the latest version.

Command Block (Download Binary):

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

Executable Permissions

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

Verify the installation by running the command.

docker run hello-world

Troubleshooting Common Issues

Issue 1: “Docker command not found” (Usually implies the service isn’t started or PATH issues).

Issue 2: “Permission Denied” (Remind them to log out and log back in if the usermod command didn’t apply immediately).

Conclusion

You have successfully installed Docker and Docker Compose on Amazon Linux 2023 and configured the necessary permissions. Your EC2 instance is now ready to handle containerized workloads, from simple web apps to complex microservices.

What’s Next? A container engine is useless without an application to run. If you are building a web stack, your next step is likely to configure your backend environment.

Next Step: Check out my guide on Setting up PHP 8.4 on Amazon Linux 2023 to get your application layer running.

Did you encounter any permission issues with the ec2-user? Let me know in the comments below, and I’ll help you troubleshoot

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply