#!/bin/sh
for DB in $(psql -U backend -t -c "SELECT datname from pg_database where datname = 'backend'"); do
echo "Loading PostGIS extensions into $DB"
psql -U backend -d $DB -c "CREATE EXTENSION IF NOT EXISTS postgis";
done
The username and password are defined in the file.yml of kubernetes cluster.
I’m able to create the postgres db and connect to it, the problem that I did’nt found the postgis extension installed. I deleted the image of the postgres db and recreated it but no vain. I didn’t understand what may the problem is? Does the container was not able to execute the postgis script at the begining or does it due to the virtual machine?
Thank you for your answer. I tried into two different machines. In the first the extension was created the successfully and in the second not. I delete the image and recreated it many times and I’m not able to got it. That’s why I want know if there is something that the container take into consideration to run the script or something else prohibt it from executin.
The syntax you’re trying to use here isn’t standard Bourne shell syntax. While there’s a popular GNU variant of the shell with many extensions in widespread use, Docker containers won’t necessarily have it installed, and Debian-based systems won’t have it available as /bin/sh.
If you look at docker logs on your container you’ll probably see a syntax error. Do you have any more information than just “it didn’t work”?
I edited the postgis.sh and I didn’t get any message about the extension in the logs of the container. I’m able to create the extension manually with the script postgis.sh when I executed it inside the container but I didn’t understand why this script was not able to be executed automatically when the container was created.
I updated the psotgis.sh file and when I run the logs of the container I didn’t get the message
Loading PostGIS extensions into $DB
from the script shell.However when I run the script inside the container it works well and the extension was created. I didn’t understand why the script didn’t been executed when the container was created.
I search through the net and I found that at the beginning docker-entrypoint.sh executes all the scripts under docker-entrypoint.d.The scripts exuctes only the first time when there is no persistant volume data. So should I delete all the data to get the extension created?