alltej
alltej

Reputation: 7285

Dockerfile ENV available in the .env file

I have an ENV set in Dockerfile:

...
ENV APP_HOME=/myapp
...

I also have a .env file.:

DATA_DIR=$APP_HOME/data

If I run the image with the env file:

docker run --env-file .env app_image

and echo the env variables in the shell(bash),

$ echo $DATA_DIR

$APP_HOME/data

I was expecting:

/myapp/data

My question is, how can I pass the ENV set during the docker build to the .env file?

Upvotes: 0

Views: 430

Answers (1)

Nguyen Lam Phuc
Nguyen Lam Phuc

Reputation: 1431

My question is, how can I pass the ENV set during the docker build to the .env file?

The short answer is that it is not possible.

The reason is that .env will not execute any bash command or take in any other external environment variables and hence the docker run command will just pass in the literal string.

As a result, you will see the value of $APP_HOME/data

Upvotes: 1

Related Questions