0

I want to compose two environment variables: first define a "root" and in the same line use that to create a composed one. In example, filename and append extension.

Doing this container,

FROM centos:7

ENV ROOT_VAR=stringy ROOT_VAR_TGZ=${ROOT_VAR}.tar.gz

RUN echo ${ROOT_VAR} $ ${ROOT_VAR_TGZ}

The output for echo is

stringy $ .tar.gz

But when splitting each variable in an individual ENV command is composed correctly. Is this the expected behaviour?

lucasvc
  • 767
  • 1
  • 11
  • 35
  • Possible duplicate of [Dockerfile: Setting multiple environment variables in single line](https://stackoverflow.com/questions/45529121/dockerfile-setting-multiple-environment-variables-in-single-line) – dfundako Sep 05 '19 at 14:02
  • Yes, I saw it, but I want to **compose second variable**, not only single line :) – lucasvc Sep 05 '19 at 14:10

1 Answers1

0

The behaviour is clearly explained in the docker reference document:

Environment variable substitution will use the same value for each variable throughout the entire instruction. In other words, in this example:

ENV abc=hello
ENV abc=bye def=$abc
ENV ghi=$abc

will result in def having a value of hello, not bye. However, ghi will have a value of bye because it is not part of the same instruction that set abc to bye.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Thaveedu
  • 101
  • 1
  • 8