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.
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 useterraform version
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.
Navigate into the working directory
In the working directory, create a file called
main.tf
- Inside
main.tf
, we need to write the below code
- provision the NGINX server container with
apply
. When terraform asks you to confirm typeyes
and pressENTER
Verify the existence of the NGINX container by visiting
http://localhost:8000
in your web browser or runningdocker 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.
- To stop the container, run
terraform destroy
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