Provisioning NGINX server using docker with terraform on linux

Provisioning NGINX server using docker with terraform on linux

First, let's look into some of the terms that we have in our blog title.

Docker :

  • Docker is a containerization tool. or In short, Docker is an open platform for developing, shipping and running applications.
  • Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.

Terraform :

  • Terraform is an open-source infrastructure as code tool that lets you build, change, and version cloud and on-prem resources safely and efficiently.

NGINX :

  • NGINX is a powerful open-source software for web serving, reverse proxying, caching, load balancing, media streaming, and more.

  • It offers faster loading times and better performance than most other web servers like Apache.

Linux :

  • Linux is an opensource Multiuser operating system

Now, it's time to get into our project.

  1. First, we need to make sure docker and terraform are installed in our system. To verify the docker installation use docker -v and to verify terraform installation use terraform version

  2. Create a directory named learn-terraform-docker-container

  • This working directory is the storage place of the configuration files that you write to describe the infrastructure you want Terraform to create and manage. When you initialize and apply the configuration here, Terraform uses this directory to store required plugins, modules (pre-written configurations), and information about the real infrastructure it created.
  1. Navigate into the working directory

  2. In the working directory, create a file called main.tf

image

  1. Inside main.tf, we need to write the below code

image

  1. provision the NGINX server container with apply. When terraform asks you to confirm type yes and press ENTER

image

  1. Verify the existence of the NGINX container by visiting http://localhost:8000 in your web browser or running docker ps to see the container.

    • docker ps is a command in docker used to list all the containers.

    • Here we checked both ways, please refer below images for the same.

image

image

  1. To stop the container, run terraform destroy

image

Now, we have successfully provisioned and destroyed an NGINX webserver with Terraform in Linux OS.

That's it for this blog, see you all in the next one with yet another concept.

Hope you enjoyed reading this blog and also learned something new.

Please feel free to share your feedback on this blog by doing like👍, share🤝, and commenting✍️ below.

For more such content related to DevOps, please follow Nagacharan

Did you find this article valuable?

Support Nagacharan by becoming a sponsor. Any amount is appreciated!