Compose: Incorrect environment variable interpolation

Created on 10 Jan 2018  路  5Comments  路  Source: docker/compose

When the .env file has the following setup:

POSTGRES_DB=test
POSTGRES_USER=test

with the following docker-compose.yml section:

  service_name:
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-${POSTGRES_USER}}
      POSTGRES_USER: ${POSTGRES_USER:-postgres}

When the container is run the POSTGRES_DB is incorrectly evaluated to value "test}" .
Expected correct POSTGRES_DB value is "test".

When either .env file is not present or the docker-compose.yml file doesn't use nested variable interpolation, the POSTGRES_DB is correctly evaluated to "test".

> docker-compose version
docker-compose version 1.17.1, build unknown                                                                                                                                                                                                  
docker-py version: 2.6.1
CPython version: 3.6.3
OpenSSL version: OpenSSL 1.1.0g  2 Nov 2017

> uname -a
Linux username 4.14.6-1-ARCH #1 SMP PREEMPT Thu Dec 14 21:26:16 UTC 2017 x86_64 GNU/Linux

> docker  version
Client:                                                                                                                                                                                                                                       
 Version:      17.11.0-ce
 API version:  1.34
 Go version:   go1.9.2
 Git commit:   1caf76ce6b
 Built:        Sun Dec 10 10:15:57 2017                                                                                                                                                                                                       
 OS/Arch:      linux/amd64                                                                                                                                                                                                                    

Server:
 Version:      17.11.0-ce
 API version:  1.34 (minimum version 1.12)
 Go version:   go1.9.2
 Git commit:   1caf76ce6b
 Built:        Sun Dec 10 10:16:13 2017
 OS/Arch:      linux/amd64
 Experimental: false

areconfig kinquestion stale

Most helpful comment

Then please consider this a feature request.

All 5 comments

There are other cases of incorrect variable interpolation with nested placeholders which does NOT involve the .env file at all.

Thanks for the report! Unfortunately, Compose's implementation doesn't actually support nested interpolation ; as a result, this is behaving as intended, with the first closing brace delimiting the variable statement, the second closing brace is treated as a regular character.

Then please consider this a feature request.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because it had not recent activity during the stale period.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leiblix picture leiblix  路  3Comments

bergtwvd picture bergtwvd  路  3Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  路  3Comments

AvdN picture AvdN  路  3Comments

saulshanabrook picture saulshanabrook  路  3Comments