Terraform + Nginx + Docker

adkarigar
1 min readSep 5, 2020

--

lets spinup…..

Start Docker

$ docker-machine start default
$ docker-machine ip
192.168.99.100

main.tf

provider "docker" {
host = "tcp://192.168.99.100:2376/"
}

config.tf

resource "docker_image" "nginx" {
name = "nginx:1.11-alpine"
}
resource "docker_container" "nginx-server" {
name = "nginx-server"
image = "${docker_image.nginx.name}"
ports {
internal = 80
external = 80
}
volumes {
container_path = "/usr/share/nginx/html/index.html"
host_path = "/c/Users/elliot123/Desktop/index.html"
}
}

index.html

<html>
<header>
<title>This is title</title>
</header>
<body>
Hello world...
</body>
</html>

Initiate Terraform Directory

$ terraform init

Build

$ terraform apply

verify

$ curl 192.168.99.100
<html>
<header><title>This is title</title></header>
<body>
Hello world...
</body>
</html>

--

--

No responses yet