Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variables in Docker

Tags:

docker

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.

like image 965
KahPhi Avatar asked Oct 17 '25 14:10

KahPhi


1 Answers

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"

like image 64
VonC Avatar answered Oct 19 '25 10:10

VonC