debugdockerMinor
How to ensure that the docker build fails if an ENV has not been set?
Viewed 0 times
thefailsdockerensurebeenhasthathowenvnot
Problem
This github discussion was found. It seems that it is allowed to build a docker image while a certain ENV does not have been set.
How to ensure that the docker build fails if an ENV has not been set?
How to ensure that the docker build fails if an ENV has not been set?
Solution
An empty of non existent environment variable is the same thing, there's no reason Docker do not allow you to pass an empty variable as it could be a valid use case.
It's up to your responsibility to ensure needed environment variables are there and give an error message back when not.
Something like this:
You can play with the exit code to automate some actions on failure around your
It's up to your responsibility to ensure needed environment variables are there and give an error message back when not.
Something like this:
RUN if [ -z "$AN_ENV_VAR" ]; then echo 'Environment variable AN_ENV_VAR must be specified. Exiting.'; exit 1; fiYou can play with the exit code to automate some actions on failure around your
docker build command.Code Snippets
RUN if [ -z "$AN_ENV_VAR" ]; then echo 'Environment variable AN_ENV_VAR must be specified. Exiting.'; exit 1; fiContext
StackExchange DevOps Q#1551, answer score: 8
Revisions (0)
No revisions yet.