-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker entrypoint fails to run shell scripts that contain the psql
command if PGHOST
environment variable is set
#318
Comments
@mishaschwartz I'm not sure what your use case is here? You can just stick any shell script into /docker-entrypoint-initdb.d/ and you can execute sql using psql and the entrypoint script will make sure that the database is running when that script is run. I'm actually planning on moving all the docker base images out to it's own repo so that we don't need to deal with rebuilding the images so often either locally or in CI when those base images rarely change. This will also let us make sure to update those base images on a cron to make sure that we are getting updates from upstream better. |
Thanks for the reply @bitner
There's no specific use-case, the behaviour is just unexpected. I would never have guessed that the init scripts would fail depending on whether these environment variables are set or not. I proposed a programmatic solution to this in #319 but I'm also happy to just make sure that this behaviour is documented somewhere so that developers aren't surprised by this behaviour like I was.
That sounds great! But won't this surprising behaviour still exist, the code will just be in a different repo? |
The reality is that I only included that script because I misunderstood how I could be doing something else, so it will go away completely. That script is inherited from the official Postgres Docker image, if there is anything that you'd like changed there, I would direct you to address this there. |
Ok good to know. Thanks for the help. Should I close #319 then? |
The pgstac docker entrypoint has a
process_init_files
function that can run or source shell scripts or run psql files using thedocker_process_sql
as a drop-in replacement for thepsql
command.Before this command is run, a temporary server is started with the
docker_temp_server_start
function which starts the server at a socket.docker_process_sql
ensures thatpsql
connects to the socket by settingPGHOST
andPGHOSTADDR
to be empty:pgstac/docker/pgstac/dbinit/docker-entrypoint.sh
Line 197 in 6c569c0
If the shell script is run (not sourced) and if the shell script contains the
psql
command, thenPGHOST
andPGHOSTADDR
are not set to be empty for thepsql
command in the shell script (which is run in a subprocess). This means that ifPGHOST
andPGHOSTADDR
are set to anything other than empty,psql
will try to connect to a probably non-existent host and will fail.STEPS TO REPRODUCE
This works fine:
The same command with the
PGHOST
environment variable set:results in the following logs:
The text was updated successfully, but these errors were encountered: