Inline substitution for ENV variables

Issue Type : Inline substitution of ENV variables
OS Version / Build :  Darwin Kernel Version 15.5.0  -- OS X El Capitan Version : 10.11.5 (15F34)
App version : Docker version 1.11.1, build 5604cbe

I am trying to use inline replacement within ENV statements. From what I have tested, inline replacement of variables defined with the ENV keyword works for statements like EXPORT, COPY, etc.

For example :

ENV HTTP_PORT 8080
ENV HTTPS_PORT 8443
....
EXPOSE ${HTTP_PORT} ${HTTPS_PORT}

and if I use the following parameters for the “run” command :

$ docker run -it --rm -e HTTP_PORT='8888' -e HTTPS_PORT='8553' ....
$ docker inspect my_container | grep HTTP
                "HTTP_PORT=8888",
                "HTTPS_PORT=8553",
$ docker port my_container
8553/tcp -> 0.0.0.0:443
8888/tcp -> 0.0.0.0:80

So, all good there. But now if I use those same variables in another one defined with the ENV keyword :

ENV HTTP_PORT 8080
ENV HTTPS_PORT 8443
....
ENV JAVA_OPTS -Xmx1024m -Xms1024m -Dcontainer.port.http=$HTTP_PORT -Dcontainer.port.https=$HTTPS_PORT

I end up getting the following for JAVA_OPTS (which is what the default values are, not what was provided in the “run” command) :

$ docker inspect my_container
                    ....
                    "Env": [ ....
                        "HTTP_PORT=8888",
                        "HTTPS_PORT=8553",
                        "JAVA_OPTS=-Xmx1024m -Xms1024m -Dcontainer.port.http=8080 -Dcontainer.port.https=8443",
                        ...
                    ], ....

Notice that the values provided for the variables HTTP_PORT and HTTPS_PORT in JAVA_OPTS are the default values (8080 and 8443) and not the ones that were provided in the run command (8888 & 8553) even though they were properly substituted as shown by the output of those variables.

So I am wondering if this is a bug since the documentation states the following :

Environment variables are supported by the following list of instructions in
the Dockerfile:

ADD
COPY
ENV
EXPOSE
LABEL
USER
WORKDIR
VOLUME
STOP
SIGNAL

Now during the build process I have noticed that the variables weren’t replaced by their default values (which seems proper), so I am assuming this might be an issue in the “run” command inline substitution logic ?

Step 8 : ENV JAVA_OPTS -Xmx1024m -Xms1024m -Dcontainer.port.http=$HTTP_PORT -Dcontainer.port.https=$HTTPS_PORT
—> Running in da069741217f
—> 04ee845f2d83

Any suggestions on how to make this work if this is NOT a bug ?

Thanks –
Nicolas.

Hi Nicolas,

I don’t believe this is a bug and that the problem is what you are expecting and what is actually happening are different. The JAVA_OPTS variable is set with the value of HTTP_PORT (et al.) during the build phase - so it is not reevaluating JAVA_OPTS when HTTP_PORT is changed in your RUN parameters.

May be misunderstanding your issue, but that is my 2-cents.