Here is a snippet of my Dockerfile:
ENV LOG_AS_JSON=false
ENV JAVA_OPTS="-Djson.logging=$LOG_AS_JSON"
When I try to pass the variable with the following command it is still set to the default value ‘false’:
docker run --detach --publish 8080:8080 --env LOG_AS_JSON=true --name app-json some_name:latest
2
Answers
You would have to explicitly overwrite the
JAVA_OPTS
variable:You first issue is that the expression is already evaluated at build time. So what’s in the image is
To prevent the build-time evaluation, you can use single quotes, so the statement becomes
Then, to get the container to actually replace the variable, you can use the
eval
command. Here I set a new variable, ‘foo’, to echo the contents of the variable and theneval
the new variable and it prints out-Djson.logging=true
.