Dockerfile - set ENV to result of command

Sultanen picture Sultanen · Jan 20, 2016 · Viewed 47.9k times · Source

Is it possible to set a docker ENV variable to the result of a command? Like:

ENV MY_VAR whoami

i want MY_VAR to get the value "root" or whatever whoami returns

Answer

Dimitrie Mititelu picture Dimitrie Mititelu · Jun 16, 2016

As an addition to DarkSideF answer.

You should be aware that each line/command in Dockerfile is ran in another container.

You can do something like this:

RUN export bleah=$(hostname -f);echo $bleah;

This is run in a single container.