DEV Community

Cover image for πŸš€ Spinning Up Containers with Terraform + Docker!
Surender Gupta
Surender Gupta

Posted on

πŸš€ Spinning Up Containers with Terraform + Docker!

Just provisioned an NGINX container using Terraform with the Docker provider πŸ’»πŸ³

Infrastructure as Code (IaC) makes container management super efficient, consistent, and scalable. With just a few lines of code, I:

  • Pulled the official NGINX image
  • Created a container named "tutorial"
  • Exposed it on port 8000
  • All automated through Terraform!

Here’s a sneak peek from the main.tf file:

resource "docker_image" "nginx" {
  name         = "nginx"
  keep_locally = false
}

resource "docker_container" "nginx" {
  image = docker_image.nginx.image_id
  name  = "tutorial"

  ports {
    internal = 80
    external = 8000
  }
}

Enter fullscreen mode Exit fullscreen mode

This is just the beginningβ€”planning to scale this with multi-container setups, networks, and persistent storage.

πŸ”§ Tech used: Terraform, Docker, NGINX

πŸ’‘ Conclusion:
This setup is a simple yet powerful example of how IaC can streamline containerized development. Whether for testing, staging, or production environments, tools like Terraform allow you to build, scale, and destroy infrastructure with confidence and repeatability. Onward to more advanced setups! 🌐

β€” β€” β€” β€” β€” β€” β€” β€”
Here is the End!

✨ Thank you for reading! ✨ I hope this article helped simplify the process and gave you valuable insights. As I continue to explore the ever-evolving world of technology, I’m excited to share more guides, tips, and updates with you. πŸš€ Stay tuned for more content that breaks down complex concepts and makes them easier to grasp. Let’s keep learning and growing together! πŸ’‘

Top comments (2)

Collapse
 
nevodavid profile image
Nevo David

Tbh Ive always wanted stuff to be this easy to set up - just curious, you think most teams underuse IaC or is it just not practical for everyone?

Collapse
 
surendergupta profile image
Surender Gupta

"Honestly, I feel the same β€” having things set up this easily is a game changer. In my experience, a lot of teams do underuse Infrastructure as Code (IaC), mostly because they either underestimate its long-term benefits or feel it's too complex to implement early on. But once it's in place, the consistency and automation it brings are hard to beat. That said, for smaller teams or fast prototypes, it might feel like overhead β€” so it’s not always practical right out of the gate."