Skip to content

Add ${variable-word} parameter substitution modifier to dockerfile environment replacement documentation #23165

@gnowland

Description

@gnowland

Is this a docs issue?

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/buildRelates to Dockerfiles or docker build commandstatus/triageNeeds triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions