How to change Docker ENV var?

When building a Dockerfile I often allow arguments to be configured at build time to make it easier to build only a few different containers. To do this, I use the default values ​​for ENV vars in combination with user-defined ARG s. Dockerfile example for quick testing:

 FROM busybox ARG FLAGS ENV FLAGS ${FLAGS:-} RUN echo "${FLAGS}" 

This can be used as follows:

 docker build --build-arg FLAGS="foo --remove-me" -t <imagename>:<tag> . 

Now I am in a situation where I want to actively remove a certain flag (in the above example: --remove-me ) from the command that I allow to run (due to an error that has been fixed no more than a year), although I know how to remove flag in other situations:

 LC_ALL=C sed -e 's/ --remove-me//' 

I ran into a problem that I have no idea how to pass and remove a flag. I know that I can do this when using RUN , but then I would have to repeat above sed using for each RUN statement, so without making it repeatable.

+6
source share
1 answer

After reading the shell replacement in this AskUbuntu answer , I gave it a try:

 ENV FLAGS ${FLAGS//--fully-static/} 

However, I encountered the following error:

 Missing ':' in substitution: "${FLAGS:-}" | "${FLAGS//--fully-static/}" 

At first I found out that Docker only supports a limited bit of bash variable replacement methods . Finally, I was able to find the shell_parser.go file in the Docker GitHub Repo , where it’s clear what should be there : which actively kills any efforts aimed at this route right at the first stage.

0
source

All Articles