terraform-docker-nginx

By | August 22, 2025

Infrastructure as Code (IaC) with Terraform

πŸš€ Objective

Provision a local Docker container using Terraform.


🧰 Tools Used

  • Terraform
  • Docker

πŸ“ Project Structure

terraform-docker-app/

β”œβ”€β”€ main.tf

β”œβ”€β”€ apply-log.txt

β”œβ”€β”€ README.md

πŸ“ Steps Performed

1. βœ… Wrote Terraform Configuration

File: main.tf

  • Pulled the officialΒ nginxΒ Docker image.
  • Created a container namedΒ nginx-container.
  • Exposed container portΒ 80Β to host portΒ 8081Β (sinceΒ 8080Β is used by Jenkins).

2. βœ… Terraform Commands Used

terraform init # Initialize the project

terraform plan # See execution plan

terraform apply # Apply infrastructure changes

tee # log the output

terraform destroy # Tear down the infrastructure

🌐 Access the Container

After applying the configuration, open your browser:

http://localhost:8081 You’ll see the nginx default welcome page.

πŸ§ͺ Verification

To confirm the container is running:

docker ps

πŸ—‘οΈ Clean Up

To remove the container:

terraform destroy -auto-approve

βœ… Screrenshots : 

image

Leave a Reply

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