Container

The container resource allows you to create Docker containers.

Examples

Minimal Example

resource "container" "unique_name" {
  network {
    id         = resource.network.cloud.meta.id
    ip_address = "10.16.0.203"
    aliases    = ["my_unique_name_ip_address"]
  }

  image {
    name = "consul:1.6.1"
  }
}

Full Example

resource "container" "unique_name" {
  depends_on = ["resource.container.another"]

  network {
    id         = resource.network.cloud.meta.id
    ip_address = "10.16.0.200"
    aliases    = ["my_unique_name_ip_address"]
  }

  image {
    name     = "consul:1.6.1"
    username = "repo_username"
    password = "repo_password"
  }

  command = [
    "consul",
    "agent"
  ]

  environment = {
    CONSUL_HTTP_ADDR = "http://localhost:8500"
  }

  volume {
    source      = "./config"
    destination = "/config"
  }

  port {
    local  = 8500
    remote = 8500
    host   = 18500
  }
  
  port_range {
    range       = "9000-9002"
    enable_host = true
  }

  privileged = false
}

Last updated