Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker running script in entrypoint

In Dockerfile I have defined an entrypoint:

ENTRYPOINT ["sh", "./docker-entrypoint.sh"]

In the docker-entrypoint.sh, I want to create a file (file.json) from the template.json, which is nothing but replaces some environment variables with actual values.

#! /bin/bash

eval "echo \"$(<template.json)\"" > file.json; npm start

Now, after getting in the container, I see file.json is empty. But if I execute the exact same command in the bash prompt inside the container, it works, and I see the required contents in file.json.

Why is this behaviour ?

like image 937
VISHAL DAGA Avatar asked Jul 22 '26 08:07

VISHAL DAGA


2 Answers

The problem is with your interpreter: sh Try exec form: ENTRYPOINT ["/bin/bash", "-c", "./docker-entrypoint.sh"]

like image 121
deosha Avatar answered Jul 24 '26 20:07

deosha


You use sh:

ENTRYPOINT ["sh", "./docker-entrypoint.sh"]

But in your entrypoint file you use bash:

#! /bin/bash

You have to choose

like image 21
veben Avatar answered Jul 24 '26 22:07

veben



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!