docs
docs copied to clipboard
Add ${variable-word} parameter substitution modifier to dockerfile environment replacement documentation
Is this a docs issue?
- [x] My issue is about the documentation content or website
Type of issue
Information is incorrect
Description
Environment replacement documentation is missing the following bash string parameter substitution modifier:
${variable-word}
Per 10.2. Parameter Substitution - The Linux Documentation Project
"${parameter-default} and ${parameter:-default} are almost equivalent. The extra : makes a difference only when parameter has been declared, but is null.
Meaning that if you want to set a default for an environment variable ONLY if it is not declared, but not null, you must use - without the :. For example:
-# Dockerfile ARG HTTP_PROXY ENV http_proxy=${HTTP_PROXY-http://my-proxy.com:1234} RUN echo $http_proxy # No build arg $ docker build -f Dockerfile . > http://my-proxy.com:1234 # Build arg null (this is the difference!) $ docker build --build-arg HTTP_PROXY="" -f Dockerfile . > # Build arg value $ docker build --build-arg HTTP_PROXY="override" -f Dockerfile . > override:-# Dockerfile ARG HTTP_PROXY ENV http_proxy=${HTTP_PROXY:-http://my-proxy.com:1234} RUN echo $http_proxy # No build arg $ docker build -f Dockerfile . > http://my-proxy.com:1234 # Build arg null (this is the difference!) $ docker build --build-arg HTTP_PROXY="" -f Dockerfile . > http://my-proxy.com:1234 # Build arg value $ docker build --build-arg HTTP_PROXY="override" -f Dockerfile . > override
Tested and confirmed locally.
Location
https://docs.docker.com/reference/dockerfile/#environment-replacement
Suggestion
Update documentation to include the ${variable-word} bash string parameter substitution modifier.