
How to Install Docker on an AWS EC2 Instance – Step-by-Step Guide
Jun 03, 2025 2 Min Read 504 Views
(Last Updated)
If you’re diving into the world of containers and cloud computing, you must install Docker with AWS EC2, which becomes a powerful move. Whether you’re a developer deploying microservices or just exploring containerization, setting up Docker on EC2 is a must-know skill.
In this guide, I’ll walk you through installing Docker on an EC2 instance, from scratch. Let’s get rolling!
Table of contents
- Prerequisites
- Step 1: Connect to Your EC2 Instance
- For Amazon Linux:
- For Ubuntu:
- Step 2: Update System Packages
- For Amazon Linux:
- For Ubuntu:
- Step 3: Install Docker
- For Amazon Linux 2:
- For Ubuntu:
- Step 4: Start and Enable Docker
- Step 5: Verify Docker Installation
- Step 6: Run Docker Without Sudo (Optional)
- Step 7: Enable Docker on Boot (Optional)
- Step 8: Use Docker on AWS
- Conclusion
Prerequisites

Before we get started, make sure you’ve got the following lined up:
- An AWS account
- An EC2 instance (Amazon Linux 2, Ubuntu, or your preferred OS)
- SSH access to the instance via a .pem key
Step 1: Connect to Your EC2 Instance

Once your EC2 instance is up and running, connect to it using SSH. Here’s how you do it:
For Amazon Linux:
bash
ssh -i /path/to/your-key.pem ec2-user@your-ec2-instance-ip
For Ubuntu:
bash
ssh -i /path/to/your-key.pem ubuntu@your-ec2-instance-ip
Step 2: Update System Packages
Before installing any software, it’s always good practice to update your system:
For Amazon Linux:
bash
sudo yum update -y
For Ubuntu:
bash
sudo apt update -y && sudo apt upgrade -y
Step 3: Install Docker
Time to bring Docker on board!
For Amazon Linux 2:
bash
sudo amazon-linux-extras enable docker
sudo yum install docker -y
For Ubuntu:
bash
sudo apt install -y docker.io
Step 4: Start and Enable Docker
Let’s make sure Docker is running and set to start on boot:
bash
sudo systemctl start docker
sudo systemctl enable docker
Step 5: Verify Docker Installation
Check if Docker is installed properly:
bash
docker --version
To make sure it’s functioning, run the classic “hello-world” container:
bash
sudo docker run hello-world
Step 6: Run Docker Without Sudo (Optional)
By default, Docker commands need root privileges. If you’d prefer to run Docker as a regular user:
bash
sudo usermod -aG docker $USER
newgrp docker
Note: You might need to log out and back in for this to take effect.
Step 7: Enable Docker on Boot (Optional)
If you want Docker to start when your EC2 instance reboots: automatically
bash
sudo systemctl enable docker
Step 8: Use Docker on AWS

That’s it! You’ve got Docker running on your EC2 instance. You can now:
- Pull images from Docker Hub
- Run and manage containers
- Deploy your apps in a scalable and efficient way
If you want to learn Cloud Computing deeply through AWS, consider enrolling in GUVI’s The
AWS Fundamentals Online Course will arm you with the skills and knowledge to engage with the power of AWS cloud services.
Conclusion
Installing Docker on an AWS EC2 instance is simpler than you might think. With just a few commands, you unlock the power of containerization in the cloud. Whether you’re testing locally or deploying production workloads, Docker on EC2 gives you a flexible foundation.
Happy containerizing!
Did you enjoy this article?