A Beginner-Friendly Guide to Docker Containers on AWS EC2

In today’s cloud-native world, Docker Containers have completely changed the way applications are developed, deployed, and managed. Containers are lightweight, fast, portable, and incredibly efficient compared to traditional virtual machines.

In this blog, we will learn:

✨ What Docker is
✨ Important Container Terminologies
✨ How to Install Docker on AWS EC2
✨ How to Run and Manage Containers
✨ How to Launch an NGINX Web Server using Docker
✨ How to Expose Applications to the Internet

Let’s dive in! πŸ”₯


πŸ“¦ What is Docker?

Docker is a powerful Containerization Platform that allows developers to package applications along with all dependencies into lightweight containers.

Containers ensure that applications run consistently across:

  • Development
  • Testing
  • Production

🧠 Important Container Terminologies


🌐 1. Container Registry

A Container Registry is a repository where container images are stored.

There are two types:

  • 🌍 Public Registry
  • πŸ”’ Private Registry

Popular Registries:


βš™οΈ 2. Container Runtime Engine

The Container Runtime Engine manages containers.

It performs operations like:
βœ… Start
βœ… Stop
βœ… Delete
βœ… Run Containers

Example:

Docker Engine

πŸ–ΌοΈ 3. Container Image

A Container Image acts as a blueprint for containers.

It contains:

  • Application Code
  • Libraries
  • Dependencies
  • Configuration Files
  • Binary Files

πŸ“¦ 4. Container

A Container is a running instance of a Container Image.

Key Features:

✨ Lightweight
✨ Fast
✨ Portable
✨ No separate Operating System required

Containers share the kernel of the Host OS.


πŸ–₯️ 5. Container Host

The machine where containers run is called the Container Host.

Example:

AWS EC2 Instance

☁️ Docker Lab β€” Launching Containers on AWS EC2


πŸš€ Step 1 β€” Launch an EC2 Instance

Go to AWS Console β†’ EC2 β†’ Launch Instance

Choose:

βœ… Amazon Linux Instance


πŸ” Step 2 β€” Connect to EC2 using SSH

Open Terminal and run:

ssh -i key.pem ec2-user@Public-IP

Replace:

  • key.pem β†’ Your Key Pair
  • Public-IP β†’ Your EC2 Public IP

πŸ“₯ Step 3 β€” Install Docker

Run the following command:

sudo yum install docker -y

What happens?

Docker package gets installed on the EC2 instance.


▢️ Step 4 β€” Start Docker Service

sudo systemctl enable --now docker

What this does:

βœ… Starts Docker Service
βœ… Enables Auto Start during reboot


βœ… Step 5 β€” Verify Docker Status

sudo systemctl status docker

If you see:

active (running)

Docker is running successfully πŸŽ‰


πŸ”Ž Step 6 β€” Check Docker Version

docker version

This displays:

  • Docker Client Version
  • Docker Server Version

πŸ–ΌοΈ Step 7 β€” View Available Images

docker images

Initially, no images will be available.


πŸ“₯ Step 8 β€” Pull Ubuntu Image

docker pull ubuntu

What happens?

Docker downloads the Ubuntu image from Docker Hub.


πŸš€ Step 9 β€” Run a Container

docker run --name myubuntu -it ubuntu /bin/bash

🧠 Command Breakdown

OptionMeaning
–nameAssign Container Name
-iInteractive Mode
-tTerminal Access
ubuntuImage Name
/bin/bashOpen Bash Shell

πŸ“‹ Step 10 β€” View Running Containers

docker ps

πŸ“¦ Step 11 β€” View All Containers

docker ps -a

This shows:
βœ… Running Containers
βœ… Stopped Containers


▢️ Step 12 β€” Start a Container

docker start myubuntu

⏹️ Step 13 β€” Stop a Container

docker stop myubuntu

⚑ Step 14 β€” Execute Commands Inside Container

docker exec -it myubuntu ps aux

This displays running processes inside the container.


πŸ—‘οΈ Step 15 β€” Delete a Container

First stop the container:

docker stop myubuntu

Then remove it:

docker rm myubuntu

πŸ’₯ Step 16 β€” Force Delete a Container

docker rm myubuntu --force

🧹 Step 17 β€” Delete an Image

docker rmi ubuntu

🌐 Launching an NGINX Web Server Container

Now let’s deploy a real web server using Docker! πŸ”₯


πŸ“₯ Step 18a β€” Pull NGINX Image

docker pull nginx

πŸš€ Step 18b β€” Run NGINX Container

docker run --name web -d nginx

What does -d mean?

Runs the container in Detached Mode (Background).


πŸ“‹ Step 18c β€” Check Running Containers

docker ps

πŸ” Step 18d β€” Inspect Container Details

docker inspect web

Note:

Find the Container IP Address.


🌐 Step 18e β€” Test NGINX Web Server

curl http://ContainerIP

You should see the default NGINX page.


✏️ Step 18f β€” Modify NGINX Web Page

Access the container:

docker exec -it web /bin/bash

Navigate to the document root:

cd /usr/share/nginx/html

Modify the index page:

echo "Hello nginx" > index.html

Exit the container:

exit

🌍 Step 18g β€” Test Again

curl http://ContainerIP

Now the output will be:

Hello nginx

πŸŽ‰ Congratulations!
You just customized a live containerized web server.


🌎 Step 19 β€” Expose Container to the External World

Use Port Mapping:

docker run --name web -d -p 80:80 nginx

πŸ”Œ Port Mapping Explained

Host PortContainer Port
8080

🌐 Access from Browser

Open:

http://EC2-Public-IP

You will see the NGINX Web Page in your browser πŸš€


πŸ“š Essential Docker Commands Summary

CommandDescription
docker imagesList Images
docker psRunning Containers
docker ps -aAll Containers
docker pullDownload Image
docker runRun Container
docker stopStop Container
docker startStart Container
docker rmRemove Container
docker rmiRemove Image
docker execExecute Inside Container
docker inspectContainer Details

🎯 Final Thoughts

Docker has become one of the most essential tools in modern DevOps and Cloud Computing.

With Docker Containers you can:
βœ… Deploy Faster
βœ… Scale Easily
βœ… Reduce Infrastructure Costs
βœ… Ensure Application Consistency

Learning Docker is the first big step toward:

  • Kubernetes
  • DevOps
  • Cloud Native Applications
  • Microservices Architecture

Happy Learning & Happy Containerizing! 🐳πŸ”₯

Total Page Visits: 119 - Today Page Visits: 119

Leave a Reply

Your email address will not be published. Required fields are marked *