How to run a DOCKER NGINX server in 5 Minute!

5P1R1D
3 min readNov 12, 2022

--

Devops Blogs Series: Part 1

What is Docker?

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.
Note: Need more info related to docker you can refer here.

What and Why Terraform?

Terraform is an IAC tool, used primarily by DevOps teams to automate various infrastructure tasks. The provisioning of cloud resources, for instance, is one of the main use cases of Terraform. It’s a cloud-agnostic, open-source provisioning tool written in the Go language and created by HashiCorp.

Hopes the section will clear all the
tools we are going to use!

Let’s Code!

Fire up you code editors!!

First and foremost as we know as Cars need Engine, Engine needs Fuel to run, exactly the we will provide Engine and Fuel to our code.

terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 2.13.0"
}
}
}

provider "docker" {}

Now, as we have defined the source from where our fuel is taken, we will define the image that we want to run on docker [in our case NGINX]:

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

and last but not the least we will have to define the where this image will be created on internet and it should run, as for driving a car a road is needed right!, so this code will be the road:

resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "tutorial"
ports {
internal = 80
external = 8000
}
}

Now, that was it, we DID IT!

Now go to your terminal of if using vscode or other editors, and use the below commands to fire up your code:

terraform init #to initialise the code
terraform plan #for checking what is going to be made
terraform apply #to apply the code

So, that was it. If you need reference for the code you can visit my repo:
https://github.com/Sandeep-BlackHat/terrafrom-docker-codes/tree/main/Docker-Nginx/Basic-Nginx-Docker-Image

Keep Showing your love and support by Following me!
It encourages a lot to write more blogs like this!

--

--