Docker Community Forums

Share and learn in the Docker community.

Using Docker Compose environment variables in Dockerfile

docker

(Mophus) #1

Is it possible to use the environment variables defined in docker-compose.yaml in a Dockerfile?

Example

docker-compose.yaml:

my:
…environment:
…MY_PATH=/foo/bar

Dockerfile:

RUN mkdir ${MY_PATH}


(Dvohra) #2

Use environment to add environment variables. Alternatively add variables from a file env_file.
https://docs.docker.com/v1.8/compose/yml/#environment


(Appmodule) #3

Tou can do that with ARG in Dockerfile and args in docker-compose.yml. Please check https://docs.docker.com/compose/compose-file/#args