Dockerfile: How to replace a placeholder in environment variable with build-arg's? Dockerfile: How to replace a placeholder in environment variable with build-arg's? docker docker

Dockerfile: How to replace a placeholder in environment variable with build-arg's?


Variable expansion can only work in double-quoted strings. This is working:

ENV CONFIG "{  \  \"credentials\":{    \      \"hostname\": \"172.17.0.5\",  \      \"password\": \"PWD\", \      \"port\": \"1234\", \      \"username\": \"${USER}\"  \     },  \     \"name\":\"database\",  \     \"tags\":[]  \  }"

A simple example:

FROM alpineENV USER fooENV CONFIG "{  \  \"credentials\":{    \      \"hostname\": \"172.17.0.5\",  \      \"password\": \"PWD\", \      \"port\": \"1234\", \      \"username\": \"${USER}\"  \     },  \     \"name\":\"database\",  \     \"tags\":[]  \  }"ENTRYPOINT env | sort

_

$ docker build -t test .$ docker run -it --rm testCONFIG={    "credentials":{          "hostname": "172.17.0.5",        "password": "PWD",       "port": "1234",       "username": "foo"       },       "name":"database",       "tags":[]    }HOME=/rootHOSTNAME=43d29bd12bc5PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPWD=/SHLVL=1TERM=xtermUSER=foo