Back to Engineering Notes
DockerEngineering Note

2. Deploy Nginx Container on Application Server

Deploy an Nginx container using the lightweight alpine image, ensure it is running, and upload a custom index.html to the web server.

🎯 Objective

Deploy an Nginx container using the lightweight alpine image, ensure it is running, and upload a custom index.html to the web server.


🧠 Concept

Docker Container → Running instance of an image
nginx:alpine → Lightweight Nginx image
Detached Mode (-d) → Run container in background
docker cp → Copy files between host ↔ container

⚙️ Step-by-Step Implementation

1️⃣ Run Nginx Container

plain text
docker run -d --name nginx_3 nginx:alpine

2️⃣ Verify Container Status

plain text
docker ps

✅ Expected:

Container: nginx_3
Status: Up

📁 Upload Custom index.html

📌 Default Nginx Web Root

Inside container:

plain text
/usr/share/nginx/html/

3️⃣ Copy index.html into Container

plain text
docker cp index.html nginx_3:/usr/share/nginx/html/index.html

4️⃣ Verify File Inside Container

plain text
docker exec -it nginx_3 ls /usr/share/nginx/html/

🌐 (Optional) Access via Browser

Run with port mapping:

plain text
docker rm -f nginx_3
docker run -d --name nginx_3 -p 80:80 nginx:alpine

Then access:

plain text
http://<server-ip>

⚠️ Edge Case Handling

🔁 Container Already Exists

plain text
docker rm -f nginx_3
docker run -d --name nginx_3 nginx:alpine

🧪 Validation Checklist

[ ] Container name is nginx_3
[ ] Image is nginx:alpine
[ ] Container is running
[ ] index.html successfully copied
[ ] Nginx serves updated content

📌 Summary

You deployed an Nginx container, uploaded a custom index.html using docker cp, and served it via the containerized web server.