How to Install Docker on Amazon Linux 2: A Complete Guide (2026)
Install Docker on Amazon Linux 2 with our comprehensive guide. Overcome common installation issues and start using Docker for AWS ECR today.
How to Install Docker on Amazon Linux 2: A Complete Guide (2026)
Installing Docker on Amazon Linux 2 can be a bit tricky, especially when common package managers like yum and amazon-linux-extras fail to find it. This guide will walk you through the process of installing Docker manually, ensuring you're ready to create Docker images for Amazon ECR effectively.
Key Takeaways
- Learn how to manually install Docker on Amazon Linux 2.
- Understand the common issues and how to troubleshoot them.
- Get ready to create and manage Docker images for Amazon ECR.
- Gain insights into Docker's importance for containerization in 2026.
Docker is an essential tool for containerizing applications, allowing developers to package their applications with all the necessary dependencies. Amazon Linux 2 is a popular choice for AWS users due to its stability and integration with AWS services. However, installing Docker isn't straightforward and requires some manual steps. This tutorial will help you overcome these challenges and successfully set up Docker on your Amazon Linux 2 instance.
Prerequisites
- Access to an Amazon Linux 2 instance with administrator privileges.
- Basic knowledge of Linux command line operations.
- Internet access from the instance to download Docker packages.
Step 1: Update Your System
Before installing Docker, it's a good practice to update your system packages to their latest versions. This ensures compatibility and security.
sudo yum update -yThis command updates all the installed packages to their latest versions available in the repository.
Step 2: Install Required Packages
Install the necessary packages that Docker depends on, such as yum-utils and others.
sudo yum install -y yum-utils device-mapper-persistent-data lvm2These packages provide essential tools for managing repositories and volumes used by Docker.
Step 3: Add the Docker Repository
Docker isn't available in the default Amazon Linux 2 repositories, so you need to add the official Docker repository.
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoThis command adds the Docker repository for CentOS, which is compatible with Amazon Linux 2.
Step 4: Install Docker
Now that the Docker repository is added, you can install Docker.
sudo yum install -y docker-ce docker-ce-cli containerd.ioThis command installs Docker Community Edition and its command-line interface.
Step 5: Start and Enable Docker
Once Docker is installed, start the Docker service and enable it to run at boot.
sudo systemctl start docker
sudo systemctl enable dockerThese commands ensure Docker starts automatically with your system.
Step 6: Verify Docker Installation
Finally, verify that Docker is installed correctly by running the following command:
docker --versionYou should see an output indicating the Docker version installed. For example:
Docker version 20.10.12, build e91ed57Common Errors/Troubleshooting
If you encounter issues during the installation, consider the following solutions:
- Docker Service Not Starting: Ensure all dependencies are correctly installed and that you have the necessary permissions.
- Network Errors: Check your internet connection and try the installation commands again.
- Repository Not Found: Verify the URL for the Docker repository and ensure it's accessible.
Conclusion
Installing Docker on Amazon Linux 2 involves a few more steps than on other distributions. By following this guide, you should now have Docker up and running, ready to build and manage containers for Amazon ECR. This setup is crucial for leveraging the power of containerization in your AWS environments.
Frequently Asked Questions
Why can't I find Docker in the default yum repository?
Docker isn't included in the default Amazon Linux 2 repositories, so you need to add Docker's official repository manually.
What if Docker doesn't start?
Ensure that all dependencies are installed and that the Docker service is enabled and started with systemctl.
How do I update Docker once installed?
Use the yum update docker-ce command to update Docker from the added repository.
Is Docker CE free to use?
Yes, Docker Community Edition (CE) is free and open-source, making it accessible for developers.
Frequently Asked Questions
Why can't I find Docker in the default yum repository?
Docker isn't included in the default Amazon Linux 2 repositories, so you need to add Docker's official repository manually.
What if Docker doesn't start?
Ensure that all dependencies are installed and that the Docker service is enabled and started with systemctl.
How do I update Docker once installed?
Use the yum update docker-ce command to update Docker from the added repository.
Is Docker CE free to use?
Yes, Docker Community Edition (CE) is free and open-source, making it accessible for developers.