Repository navigation
Description
Environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH combine values that are usually contributed from many different pieces of software.
For example, one image might install a Python library to /opt/acme and set PYTHONPATH to this value:
ENV PYTHONPATH /opt/acme
An image based on this one might install another Python library in /usr/local/lib/yoyodyne. It might try to cooperate with the underlying image:
ENV PYTHONPATH $PYTHONPATH:/usr/local/lib/yoyodyne
This may prove correct, yielding a value for the variable in the container of /opt/acme:/usr/local/lib/yoyodyne. However, it requires the author of the second image to know about the construction of the first image. It also requires them to keep themselves updated about changes to the construction of the first image. If a future version changes the way the software is installed so that PYTHONPATH no longer need be set then unless the Dockerfile for the second image is updated, the value for PYTHONPATH becomes :/usr/local/lib/yoyodyne (notice the leading :). This mostly works but it introduces an extra unintended path to the Python module search path. This may not cause any problems - or it might break the image (in a worst case outcome, perhaps it breaks the image quietly, by leaving everything with the appearance of working but introducing a subtle security issue where the Python application packaged in the second image begins evaluating arbitrary user-supplied Python code).
If full shell-style variable substitution were supported then this could be avoided by a diligent Dockerfile author:
ENV PYTHONPATH ${PYTHONPATH:+${PYTHONPATH}:}/usr/local/lib/yoyodyne
The first part of this says "If PYTHONPATH is set, substitute its value followed by :. If it is not set, substitute the empty string". The result of this substitution is then concatenated with the literal /usr/local/lib/yoyodyne. This produces either /opt/acme:/usr/local/lib/yoyodyne if PYTHONPATH is already set to /opt/acme or /usr/local/lib/yoyodyne if PYTHONPATH is not already set.
There are probably other solutions to this problem too. The more complicated shell substitution is mostly given as an example of how some existing systems account for this problem and offer a solution for it.
Activity
exarkun commentedon Oct 20, 2014
ping @erikh (as requested)
jessfraz commentedon Feb 26, 2015
ping @tiborvass @duglin
duglin commentedon Feb 26, 2015
support for more advanced env var substitution would be a good thing - just non-trivial. I'll put it on our todo list but it may not happen for a while.
duglin commentedon Mar 1, 2015
See #10431
jessfraz commentedon Mar 2, 2015
closing as dup then of #8667
jessfraz commentedon Mar 2, 2015
sorry wrong one, this one stays open