A hands-on DevOps lab demonstrating how different base images impact Docker image size, performance, security, and layers using NGINX.
This project explores:
nginx-docker-lab/
│
├── nginx-ubuntu/
│ └── Dockerfile
│
├── nginx-alpine/
│ └── Dockerfile
│
└── README.md
docker pull nginx:latest
docker run -d --name nginx-official -p 8080:80 nginx
Open:
http://localhost:8080
FROM ubuntu:22.04
RUN apt update && apt install -y nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
docker build -t nginx-ubuntu .
docker run -d --name nginx-ubuntu -p 8081:80 nginx-ubuntu
FROM alpine:3.19
RUN apk add --no-cache nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
docker build -t nginx-alpine .
docker run -d --name nginx-alpine -p 8082:80 nginx-alpine
docker images
| Image | Base OS | Approx Size |
|---|---|---|
| nginx | Official | Medium |
| nginx-ubuntu | Ubuntu | Large |
| nginx-alpine | Alpine | Small |
docker history nginx
docker history nginx-ubuntu
docker history nginx-alpine
Each Dockerfile command creates a new layer. More OS packages = larger layers.
| Feature | Official | Ubuntu | Alpine |
|---|---|---|---|
| Size | Medium | Large | Small |
| Security | Good | More attack surface | Minimal |
| Speed | Fast | Moderate | Fastest |
| Use Case | Default | Full OS apps | Cloud-native apps |
This lab proves that base image selection significantly affects Docker image size, security posture, and deployment efficiency. Alpine-based images are ideal for microservices and cloud environments, while Ubuntu provides flexibility for complex applications. Official images offer a balanced, production-ready setup.
docker stop nginx-official nginx-ubuntu nginx-alpine
docker rm nginx-official nginx-ubuntu nginx-alpine
Built for learning DevOps, Containers, and Cloud-Native best practices.