Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker run ENTRYPOINT does not replace environment variable

Tags:

docker

I have an entry point as shown here

ENTRYPOINT /usr/bin/java ... /usr/path/$FILE

I am trying to pass an environment variable while starting container

-e FILE=myfile.txt

However this value does not seem to be replaced. Java throws an exception that /usr/path is a directory . If I hard code the entrypoint with a file name in the dockerfile, it works perfectly fine.

ENTRYPOINT /usr/bin/java ... /usr/path/myfile.txt

It confirms $FILE is not replaced.

How to fix this?

NOTE:

Interestingly docker-compose works perfectly fine!!

environment:
  - FILE=myfile.txt
like image 407
KitKarson Avatar asked May 09 '26 20:05

KitKarson


1 Answers

In order to ensure that the shell form of ENTRYPOINT, that you correctly are using, does substitute the environment variable $FILE, add an exec:

ENTRYPOINT exec /usr/bin/java ... "/usr/path/$FILE"

Then check that your docker run -e FILE=xxx yourImage does work.

That supposes that your Dockefile includes an ENV FILE aDefaultFile directive, in order for docker run -e to work.

like image 167
VonC Avatar answered May 11 '26 14:05

VonC



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!