Hello lad
Hello lad

Reputation: 18790

Override ENV variable in base docker image

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?

Upvotes: 9

Views: 9564

Answers (1)

VonC
VonC

Reputation: 1323183

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   <=============

Upvotes: 3

Related Questions