Post thumbnail
CLOUD COMPUTING

How to Install Docker on an AWS EC2 Instance – Step-by-Step Guide

By Naveen Kumar

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


  1. Prerequisites
  2. Step 1: Connect to Your EC2 Instance
    • For Amazon Linux:
    • For Ubuntu:
  3. Step 2: Update System Packages
    • For Amazon Linux:
    • For Ubuntu:
  4. Step 3: Install Docker
    • For Amazon Linux 2:
    • For Ubuntu:
  5. Step 4: Start and Enable Docker
  6. Step 5: Verify Docker Installation
  7. Step 6: Run Docker Without Sudo (Optional)
  8. Step 7: Enable Docker on Boot (Optional)
  9. Step 8: Use Docker on AWS
  10. Conclusion

Prerequisites

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

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.

MDN

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

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.

MDN

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!

Career transition

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Share logo Copy link
Power Packed Webinars
Free Webinar Icon
Power Packed Webinars
Subscribe now for FREE! 🔔
close
Webinar ad
Table of contents Table of contents
Table of contents Articles
Close button

  1. Prerequisites
  2. Step 1: Connect to Your EC2 Instance
    • For Amazon Linux:
    • For Ubuntu:
  3. Step 2: Update System Packages
    • For Amazon Linux:
    • For Ubuntu:
  4. Step 3: Install Docker
    • For Amazon Linux 2:
    • For Ubuntu:
  5. Step 4: Start and Enable Docker
  6. Step 5: Verify Docker Installation
  7. Step 6: Run Docker Without Sudo (Optional)
  8. Step 7: Enable Docker on Boot (Optional)
  9. Step 8: Use Docker on AWS
  10. Conclusion