Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass environment variables to a Docker container with Terraform?

I'm spawning Docker containers using Terraform's Docker provider, but fail to understand how to pass them environment variables.

The project's documentation on the env option states :

env - (Optional, set of strings) Environment variables to set.

What is a "set of strings" in context ? Can you provide an example docker container resource declaration that uses the env option ?

like image 200
iodbh Avatar asked Nov 24 '16 10:11

iodbh


Video Answer


1 Answers

From Terraforming a Docker environment:

# Start elastic container
resource "docker_container" "elastic" {
    image = "${docker_image.elastic.latest}"
    name = "elastic"
    hostname = "elastic"
    env = ["SERVICE=elastic", "PROJECT=stage", "ENVIRONMENT=operations"]
    restart= "no"
    must_run="true"
}
like image 135
gile Avatar answered Sep 24 '22 17:09

gile