Launch an AWS EC2 Instance

Published: (December 28, 2025 at 07:57 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Introduction

This guide walks you through launching an AWS EC2 instance, installing Docker, and running NGINX inside a Docker container. By the end you will have a publicly accessible web server showing the default NGINX welcome page.

Prerequisites

  • AWS account
  • Basic terminal knowledge
  • SSH client installed on your local machine
  • Internet connection

Launch an EC2 Instance

  1. Open the AWS Console → EC2Launch Instance.
  2. Choose an AMI: Amazon Linux 2023.
  3. Select instance type: t2.micro (Free tier).
  4. Create a key pair:
    • Name: my-ec2-key
    • Type: RSA
    • Format: .pem
  5. Network settings:
    • Auto‑assign Public IP: Enabled
  6. Create a Security Group with the following inbound rules:
TypePortSource
SSH22My IP
HTTP800.0.0.0/0
  1. Click Launch Instance and wait until the instance state becomes Running.

Connect via SSH

chmod 400 my-ec2-key.pem
ssh -i ~/.ssh/my-ec2-key.pem ec2-user@

Replace the empty space after ec2-user@ with the public IP address of your instance.

Install Docker

# Update packages
sudo yum update -y

# Install Docker
sudo yum install docker -y

# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker

# Add ec2-user to the docker group
sudo usermod -aG docker ec2-user

Log out and log back in for the group change to take effect:

ssh -i ~/.ssh/my-ec2-key.pem ec2-user@

Verify Docker installation:

docker --version

Run NGINX in Docker

docker run -d --name nginx-test -p 80:80 nginx
  • Runs NGINX in detached mode
  • Exposes port 80 to the public

Check that the container is running:

docker ps

You should see a line similar to:

0.0.0.0:80->80/tcp

Verify Public Access

Open a web browser and navigate to:

http://<public-ip>

You should see the default NGINX welcome page:

Welcome to nginx!

This confirms that your EC2 instance is publicly accessible and serving content via Docker.

Back to Blog

Related posts

Read more »

Day 12.Attach Volume to EC2 Instance

Lab Information The Nautilus DevOps team is creating services on AWS and breaking the migration into smaller tasks for better control, risk mitigation, and res...

Amazon EC2 Instance Installation.

!Cover image for Amazon EC2 Instance Installation.https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev...

Creating an EC2 Instance

Steps 1. Search bar, type EC2 and choose the first option. 2. Click Launch Instance. 3. In the Launch Instance Environment, enter a name in the name bar and cl...

Day 16.Create IAM User

!Cover image for Day 16.Create IAM Userhttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads...