How to Install Docker on Amazon EC2 Linux: A Step-by-Step Guide
Docker has become an essential tool for developers and system administrators. This guide will walk you through the process of installing Docker on an Amazon EC2 Linux instance.
Prerequisites
- An running Amazon EC2 instance with Amazon Linux 2
- SSH access to your EC2 instance
- Sudo privileges on the instance
Installation Steps
1. Update Your System Packages
First, connect to your EC2 instance and update all installed packages:
sudo yum update -y
2. Install Docker
Install the Docker package:
sudo yum install docker -y
3. Start and Enable Docker Service
Start the Docker service and configure it to launch on boot:
sudo systemctl start docker
sudo systemctl enable docker
4. Add Your User to the Docker Group
To avoid using sudo for every Docker command, add your user to the docker group:
sudo usermod -a -G docker ec2-user
Note: You’ll need to log out and log back in for this change to take effect. (logout from your SSH session)
5. Verify the Installation
Check if Docker is installed correctly:
docker --version
Run a test container to ensure everything works:
docker run hello-world
Common Issues and Solutions
- Permission Denied: If you get a “permission denied” error, make sure you’ve logged out and back in after adding your user to the docker group. when you type id , you should see docker group assigned to your ec2-user!
- Service Failed to Start: If Docker fails to start, check the system logs:
sudo systemctl status docker
Next Steps
Now that Docker is installed, you can:
- Pull container images from Docker Hub
- Build your own containers
- Create and manage Docker networks
- Work with Docker Compose for multi-container applications
Conclusion
You now have a working Docker installation on your Amazon EC2 Linux instance. The containerization possibilities are endless – from running development environments to deploying production applications.
Remember to follow Docker best practices and regularly update both Docker and your EC2 instance for security purposes.