8

I have a base docker image, call it docker-image with Dockerfile

FROM Ubuntu
ENV USER default
CMD ['start-application']

a customized docker image, based on docker-image

FROM docker-image
ENV USER username

I want to overwrite USER Environment Variable without changing the base-image, (before the application starts), is that possible?

Hello lad
  • 17,344
  • 46
  • 127
  • 200

1 Answers1

3

If you cannot build another image, as described in "Dockerfile Overriding ENV variable", you at least can modify it when starting the container with docker run -e

See "ENV (environment variables)"

the operator can set any environment variable in the container by using one or more -e flags, even overriding those mentioned above, or already defined by the developer with a Dockerfile ENV

$ docker run -e "deep=purple" -e today --rm alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=d2219b854598
deep=purple   <=============
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    If the underlying image needs to be modified between registries, the mutate `package` of the [go container registry tool](https://github.com/google/go-containerregistry/tree/main/pkg/v1/mutate) might be useful – danialk Dec 05 '21 at 07:06
  • 1
    @danialk Interesting. I was not aware of this. I see it used here (https://stackoverflow.com/q/69979872/6309) and here (https://stackoverflow.com/q/53528416/6309) – VonC Dec 05 '21 at 20:58