Reputation: 73
I am trying to set up our production environment in a docker image. After spending some hours compiling software, I realized that I forgot to set the locale environment variables in the Dockerfile.
Is there a way to permanently commit environment variables to an image? I only came across the dockerfile way of doing this and I don't want to rebuild from that and lose all the work already done.
Setting those variables in .bashrc
is not working, as the docker run command seems to bypass those settings.
Upvotes: 3
Views: 4187
Reputation: 2872
You can change environment variables during a "docker commit" operation to modify an existing image. See https://docs.docker.com/engine/reference/commandline/commit/ and this StackOverflow Q&A: Docker Commit Created Images and ENTRYPOINT - and reference the answer by sxc731. It is not clear to me how one sets multiple Env variables, but it might take a separate --change for each.
Here is an example of what I was just doing (bash shell):
docker run -it --entrypoint /bin/bash $origimghash
# make changes, leave running, then in another shell:
EP='ENTRYPOINT ["python","/tmp/deploy/deploy.py"]'
ENV='Env no_proxy "*.local, 169.254/16"'
docker commit "--change=$ENV" "--change=$EP" $runninghash me/myimg
docker inspect -f "{{ .Config.Env }}" $newhash
Upvotes: 1
Reputation: 1328912
Is there a way to permanently commit environment variables to an image?
That is the directive ENV
in Dockerfile.
ENV <key> <value>
ENV <key>=<value> ...
But since you don't want to rebuild the image (although you could add it at the end of the dockerfile, and benefit from the cache for most of the image build), you can still launch your containers with docker run -e "variable=value"
Upvotes: 4