{"id":280,"date":"2025-08-22T11:24:13","date_gmt":"2025-08-22T11:24:13","guid":{"rendered":"https:\/\/myallcodes.in\/?p=280"},"modified":"2025-08-22T11:24:13","modified_gmt":"2025-08-22T11:24:13","slug":"terraform-docker-nginx","status":"publish","type":"post","link":"https:\/\/myallcodes.in\/index.php\/2025\/08\/22\/terraform-docker-nginx\/","title":{"rendered":"terraform-docker-nginx"},"content":{"rendered":"\n<p><strong>Infrastructure as Code (IaC) with Terraform<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\ude80 Objective<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/terraform-docker-nginx#-objective\"><\/a><\/p>\n\n\n\n<p>Provision a local Docker container using&nbsp;<strong>Terraform<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddf0 Tools Used<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/terraform-docker-nginx#-tools-used\"><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Terraform<\/li>\n\n\n\n<li>Docker<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcc1 Project Structure<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/terraform-docker-nginx#-project-structure\"><\/a><\/p>\n\n\n\n<p>terraform-docker-app\/<\/p>\n\n\n\n<p>\u251c\u2500\u2500 main.tf<\/p>\n\n\n\n<p>\u251c\u2500\u2500 apply-log.txt<\/p>\n\n\n\n<p>\u251c\u2500\u2500 README.md<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcdd Steps Performed<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/terraform-docker-nginx#-steps-performed\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u2705 Wrote Terraform Configuration<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/terraform-docker-nginx#1--wrote-terraform-configuration\"><\/a><\/p>\n\n\n\n<p>File:&nbsp;<code>main.tf<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pulled the official\u00a0<strong>nginx<\/strong>\u00a0Docker image.<\/li>\n\n\n\n<li>Created a container named\u00a0<code>nginx-container<\/code>.<\/li>\n\n\n\n<li>Exposed container port\u00a0<code>80<\/code>\u00a0to host port\u00a0<code>8081<\/code>\u00a0(since\u00a0<code>8080<\/code>\u00a0is used by Jenkins).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u2705 Terraform Commands Used<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/terraform-docker-nginx#2--terraform-commands-used\"><\/a><\/p>\n\n\n\n<p>terraform init # Initialize the project<\/p>\n\n\n\n<p>terraform plan # See execution plan<\/p>\n\n\n\n<p>terraform apply # Apply infrastructure changes<\/p>\n\n\n\n<p>tee # log the output<\/p>\n\n\n\n<p>terraform destroy # Tear down the infrastructure<\/p>\n\n\n\n<p>\ud83c\udf10 Access the Container<\/p>\n\n\n\n<p><strong>After applying the configuration, open your browser:<\/strong><\/p>\n\n\n\n<p><a href=\"http:\/\/localhost:8081\/\">http:\/\/localhost:8081<\/a>&nbsp;You\u2019ll see the nginx default welcome page.<\/p>\n\n\n\n<p>\ud83e\uddea Verification<\/p>\n\n\n\n<p>To confirm the container is running:<\/p>\n\n\n\n<p>docker ps<\/p>\n\n\n\n<p>\ud83d\uddd1\ufe0f Clean Up<\/p>\n\n\n\n<p>To remove the container:<\/p>\n\n\n\n<p>terraform destroy -auto-approve<\/p>\n\n\n\n<p>\u2705 Screrenshots :&nbsp;<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/private-user-images.githubusercontent.com\/206333559\/475359487-57bb154e-4a63-400f-937c-aaa044b2e7e6.png?jw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otQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwODIyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDgyMlQxMTIzMDhaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yOTY0YzFlMDY5ZThiNjk1NjU2ZDg1Njg0NWUzYTk2OGYyMTU4ZmIxZWNkOGQyNzkwNzBmODNhMjAzYmMwYWJjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.SQxE5tZc6y3yuhqqmEzA2nmm4vWByTLYdW77AIDeD2A\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/private-user-images.githubusercontent.com\/206333559\/475359580-d1772be8-3ff2-4dae-ad5b-98a2d2df8ed9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTU4NjIwODgsIm5iZiI6MTc1NTg2MTc4OCwicGF0aCI6Ii8yMDYzMzM1NTkvNDc1MzU5NTgwLWQxNzcyYmU4LTNmZjItNGRhZS1hZDViLTk4YTJkMmRmOGVkOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwODIyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDgyMlQxMTIzMDhaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yOTY0YzFlMDY5ZThiNjk1NjU2ZDg1Njg0NWUzYTk2OGYyMTU4ZmIxZWNkOGQyNzkwNzBmODNhMjAzYmMwYWJjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.SQxE5tZc6y3yuhqqmEzA2nmm4vWByTLYdW77AIDeD2A\" alt=\"image\"\/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Infrastructure as Code (IaC) with Terraform \ud83d\ude80 Objective Provision a local Docker container using&nbsp;Terraform. \ud83e\uddf0 Tools Used \ud83d\udcc1 Project Structure terraform-docker-app\/ \u251c\u2500\u2500 main.tf \u251c\u2500\u2500 apply-log.txt \u251c\u2500\u2500 README.md \ud83d\udcdd Steps Performed 1. \u2705 Wrote Terraform Configuration File:&nbsp;main.tf 2. \u2705 Terraform Commands Used terraform init # Initialize the project terraform plan # See execution plan terraform apply\u2026 <span class=\"read-more\"><a href=\"https:\/\/myallcodes.in\/index.php\/2025\/08\/22\/terraform-docker-nginx\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-power-shell-scripts"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":1,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":281,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts\/280\/revisions\/281"}],"wp:attachment":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}