π Managing Containers Using Docker π³
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 PairPublic-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
| Option | Meaning |
|---|---|
| –name | Assign Container Name |
| -i | Interactive Mode |
| -t | Terminal Access |
| ubuntu | Image Name |
| /bin/bash | Open 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 Port | Container Port |
|---|---|
| 80 | 80 |
π Access from Browser
Open:
http://EC2-Public-IP
You will see the NGINX Web Page in your browser π
π Essential Docker Commands Summary
| Command | Description |
|---|---|
| docker images | List Images |
| docker ps | Running Containers |
| docker ps -a | All Containers |
| docker pull | Download Image |
| docker run | Run Container |
| docker stop | Stop Container |
| docker start | Start Container |
| docker rm | Remove Container |
| docker rmi | Remove Image |
| docker exec | Execute Inside Container |
| docker inspect | Container 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! π³π₯
