2021年1月26日星期二

In Dockerfile, how to append a value to an environment variable that can exist in base image?

Let's assume we have a Dockerfile like this:

FROM SomeBaseImage:Version    ENV MyVar="MyValue"  

In case SomeBaseImage already has a value for MyVar, we usually copy that and set the new value in our Dockerfile. In our case we need to append to it. But this has a drawback:

In case a newer version of SomeBaseImage modifies the value of MyVar, we'll end up with a hard-coded value based on the older version.

Is there a way to access the environment variable from the base image (and then possibly append to it)?

P.S: From my understanding, Arg is not the answer. It allows access to arguments passed by the build command, not environment variables set in the base image.

https://stackoverflow.com/questions/65912376/in-dockerfile-how-to-append-a-value-to-an-environment-variable-that-can-exist-i January 27, 2021 at 11:08AM

没有评论:

发表评论