This project demonstrates foundational DevOps principles by deploying an Nginx web server using three distinct, progressively complex patterns. It uses Docker, Docker Compose, Python, and LocalStack to simulate a real-world cloud environment on a local machine, showcasing a journey from basic containerization to advanced, programmatic automation.
- Infrastructure as Code (IaC): Implemented both declarative (Docker Compose) and imperative (Python script) approaches, highlighting the trade-offs of each.
- Containerization & Orchestration: Created custom, multi-stage Docker images and managed a multi-container application stack with Docker Compose.
- Cloud Services Simulation: Leveraged LocalStack to mimic AWS S3 for dynamic content hosting, enabling development and testing of cloud-native patterns without an AWS account.
- Automation & Scripting: Developed a Python script using the Docker SDK (
docker-py
) to programmatically manage the entire application lifecycle, from network creation to container provisioning and cleanup. - Decoupled Architecture: Refactored a monolithic application into a dynamic system where the web server fetches its content from an object store (S3) on startup via a custom entrypoint script.
- Configuration Management: Utilized environment variables to pass configuration (API endpoints, credentials, bucket names) into containers, following Twelve-Factor App principles.
- Container Networking: Configured service-to-service communication between containers on a user-defined Docker network.
- Containerization: Docker, Docker Compose
- Cloud (Simulated): LocalStack (emulating AWS S3)
- Automation: Python 3, Docker SDK (
docker-py
), Bash Scripting - Web Server: Nginx
- CLI Tools: AWS CLI
This repository is divided into three parts, each located in its own directory and representing a different deployment pattern.
A simple, self-contained Nginx deployment where the website content is built directly into the Docker image.
📦 Teaches you how to build a static web server using Docker Compose only.
To Run:
cd part1-declarative-basic
docker-compose up -d
Access the site at http://localhost:8080
An advanced pattern where the Nginx container is generic and dynamically fetches its index.html file from a LocalStack S3 bucket on startup.
🔁 Demonstrates dynamic content loading using S3 + environment configs.
To Run:
cd part2-declarative-dynamic
docker-compose up -d localstack
docker logs -f local-aws-cloud
Wait for it to say Ready. or similar with no repeated crash logs.
ℹ️ Once LocalStack shows "Ready" in the logs, press
Ctrl + C
to exit log view, then proceed with the AWS CLI commands below.
💡 Note: Ensure AWS CLI is configured with dummy credentials:
Access Key ID: test
,Secret Access Key: test
,Region: us-east-1
You can runaws configure
to set these.
aws configure
aws --endpoint-url=http://localhost:4566 s3 mb s3://my-dynamic-website-bucket
aws --endpoint-url=http://localhost:4566 s3 cp ./nginx-web/index.html s3://my-dynamic-website-bucket/
docker-compose up -d nginx-service
Access the site at http://localhost:8080
docker-compose down
A Python script that uses the Docker SDK to build the entire environment from scratch. This script handles network creation, container provisioning (installing Nginx inside a bare Ubuntu container), and deployment.
⚙️ Automates everything using Python + Docker SDK (full control over containers).
To Run:
cd part3-imperative-python
pip install docker
python3 deploy.py
Access the site at http://localhost:8081.
python3 cleanup.py
This diagram illustrates the dynamic content flow, where the Nginx container is decoupled from its content.
This is a known issue on some systems (especially Windows) when mounting the host's /tmp
directory into LocalStack.
Fix: Use a Docker-managed named volume and set TMPDIR=/tmp/localstack-custom
in your docker-compose.yml
.
Ensure LocalStack container is running:
docker ps
docker logs local-aws-cloud
docker run -d -e SERVICES=s3 -e TMPDIR=/tmp/localstack-custom \
-v localstack_data:/tmp/localstack-custom -p 4566:4566 \
--name local-aws-cloud localstack/localstack:latest
This project is licensed under the MIT License - see the LICENSE file for details.