See below code:
I want to pass a variable from Dockerfile or wherever to my init.sql file.
How can I do this?
Dockerfile
FROM postgres
ADD init.sql /docker-entrypoint-initdb.d/
init.sql
CREATE TABLE ${SOME_ARGUMENT_HERE}(
id SERIAL PRIMARY KEY,
name VARCHAR(500) NOT NULL,
completed BOOLEAN NOT NULL);
2
Answers
Ok so far I've created this
docker-compose.yml
seed.sql
script.sh
Dockerfile
Finally fixed. I realised the problem was because my script.sh was not targeting the destination of /docker-entrypoint-initdb.d/seed.sql
You can use for example script or execute shell command using sed/awk to replace your variable
${SOME_ARGUMENT_HERE}
with some other variable that has been passed to the DockerfileExample of command
Example of shell script (replace.sh)