Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Environment Variable Not Overridden

Given I have a dockerfile like:

ARG MAX_MEMORY_PER_NODE="10GB"
ENV P_MAX_MEMORY_PER_NODE="${MAX_MEMORY_PER_NODE}"
ENTRYPOINT ["/var/p/entrypoint.sh"]

And the entrypoint.sh does something like:

echo "Max memory ${P_MAX_MEMORY_PER_NODE}"

If I were to run the container using the defaults, I would expect

Max Memory 10GB

And that works, but if I run

docker run me/mycontainer:latest -e P_MAX_MEMORY_PER_NODE=1GB

The script still uses the default value (does not print 1GB instead). In fact if I ran:

docker run me/mycontainer:latest -e A_TEST=Hello

And the script had

echo "My test: ${A_TEST}"

It would output

My test:

What am I doing wrong here? What can't I override (or even set) the environment variables being used in the entrypoint script from docker run?

like image 988
mhaken Avatar asked Dec 05 '25 04:12

mhaken


1 Answers

Set the environment variable before the image:

docker run -e "A_TEST=hello" alpine env

like image 107
Lexandro Avatar answered Dec 07 '25 20:12

Lexandro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!