F
F
furyon2016-03-20 19:26:09
LXC
furyon, 2016-03-20 19:26:09

How to use environment in Dockerfile?

Hello!
Is it possible to use environment variables in Dockerfile using docker-compose?
For example I have docker-compose.yml

app:
  build: ./
  env_file: dc.env

dc.env file:
MY_VAR="my_var"
and Dockerfile:
FROM ubuntu
RUN echo "$MY_VAR"

In this example, echo does not show what I expect, but I would like to see my_varhow to be?
Grateful for any information.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aboyev, 2016-03-22
@furyon

The fact is that the variables from env_file are initialized after the deployment of the container.
Try setting them in the Dockerfile itself:

ADD dc.env dc.env
RUN export `cat dc.env`

Similar question on SO
Closed ticket on github

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question