1

I have a Docker file which list environmental variable as follows:

ENV WORKGROUP "my-workgroup"

In python file I am accessing it as follows:

os.environ['WORKGROUP']

When I build the docker it fails with the following error:

KeyError: 'WORK_GROUP'

The reason is some environmental variables have some default values which I need to set in docker. I can override these inside docker run command when needed. Any idea how can I achieve such a scenario. Thanks.

1 Answer 1

1

I am usually doing like this in Dockerfile

ENV ENV_VAR=some_default_value

to start that kind of image and override env in image you can do this

docker run --env ENV_VAR=value_to_override

ENV_VAR will have some_default_value or value_to_override when image is started. (not during image build process). and os.environ['ENV_VAR'] sees that value just fine.

you may try docker build --no_cache so you are sure that image is rebuild completely.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.