Search code examples
docker-composeterraformjwilder-nginx-proxy

Using Terraform with docker-compose and nginx-proxy


Has anyone tried using all these tools together?

I'm currently using nginx-proxy and docker-compose for a four-container solution.

I'm now trying to make deployment better/faster/cheaper and think terraform might be the piece I'm now looking for.

My question is - does terraform work with docker-compose? Or is there too much overlap between them?

Thanks for any advice!


Solution

  • You can run single or multiple docker container in Terraform using the docker provider.

    https://www.terraform.io/docs/providers/docker/index.html

    Sample nginx terraform config

    provider "docker" {
      host = "tcp://ec2-xxxxxxx.compute.amazonaws.com:2375/"
    }
    resource "docker_image" "nginx" {
      name = "nginx:1.11-alpine"
    }
    resource "docker_container" "nginx-server" {
      name = "nginx-server"
      image = "${docker_image.nginx.latest}"
      ports {
        internal = 80
        external = 80
      }
      volumes {
        container_path  = "/usr/share/nginx/html"
        host_path = "/home/scrapbook/tutorial/www"
        read_only = true
      }
    }