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
postgres /docker-entrypoint.sh not running scripts in /docker-entrypoint-initdb.d/ #40
Comments
Random debug thought: is the script executable in the container, maybe also ownership? |
These are both possibilities, though if they were not owned/executable by the right process, it seems from this script that Docker would bail out with a non-zero exit code. https://github.com/docker-library/postgres/blob/master/docker-entrypoint.sh#L48 |
I hit this problem - the issue is that the script is only run if there is no postgres data directory ;)
I think it would be better to have the script run a "initdb" function for all brand spanking new installations, and a "always run" function hth |
There isn't any way that I know of to detect a newly created container. The
PGDATA check is probably the best this image can do.
|
sometime the scripts could be used to perform update operations on the existing data. |
I agree. The current approach makes it extremely hard to supply your own |
I too met this problem and have been trying to debug it for a week already. |
@danwyry, what are you running? Any information you can give to help us reproduce the issue? |
Sure, this is what I tryied so far:
being 'my_postgres' the directory name under which y located the Dockerfile and entrypoint. I ran docker-compose build. I performed several hardcoded tests to see where the docker-entrypoint.sh exits and realized itś not even getting past the follwing condition (which in the original file is in line 17) These are the functions I added that configure some settings on postgresql.conf (I already tested them on their own and they work ok). :
BTW, I also tryed puting these functions on an alternate script inside docker-entrypoint-init.d and creating a Dockerfile extending from the official image:
But it won't work either. |
Hmmm... I am unable to reproduce. I started with the docker-entrypoint.sh and added your functions with some output to see it works. I guessed on the values to apply. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index 87d7e3b..3334092 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -6,6 +6,16 @@ set_listen_addresses() {
sed -ri "s/^#?(listen_addresses\s*=\s*)\S+/\1'$sedEscapedValue'/" "$PGDATA/postgresql.conf"
}
+set_bytea_output() {
+ sed -ri '/^[# ]*[# ]*[# ]*bytea_output[ ]*=[ ]*.*/d' "$PGDATA/postgresql.conf"
+ echo "bytea_output = '$1'" >> "$PGDATA/postgresql.conf"
+}
+set_standard_conforming_strings() {
+ sed -ri '/^[# ]*[# ]*[# ]*standard_conforming_strings[ ]*=[ ]*.*/d' "$PGDATA/postgresql.conf"
+ echo "standard_conforming_strings = $1" >> "$PGDATA/postgresql.conf"
+}
+
if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA"
@@ -84,6 +94,13 @@ if [ "$1" = 'postgres' ]; then
gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop
set_listen_addresses '*'
+ set_bytea_output 'hex'
+ set_standard_conforming_strings 'off'
+ echo '*****************************'
+ echo '*****************************'
+ cat "$PGDATA/postgresql.conf"
+ echo '*****************************'
+ echo '*****************************'
echo
echo 'PostgreSQL init process complete; ready for start up.' Then I ran postgres with the modified entrypoint: $ docker run -it --rm -v ~/postgres/modified-docker-entrypoint.sh:/docker-entrypoint
.sh:ro -e POSTGRES_PASSWORD=password postgres:9.4 |
would you mind trying it within a docker-compose configuration to see if maybe that's making any difference? |
Hi @danwyry did you ever get your scripts running? I am having the same issue using docker-compose |
nope, couldn't do it. But I stopped trying after a while |
@danwyry, my newest idea is that the volume was persisting. With docker compose it tries really hard to keep volumes (ie your initialized database files). Most of the entrypoint script only runs on first initialization. |
Any ETA on when we would be able to easily re-launch the init script (via a command maybe?), without removing the volumes? |
I had this exact same issue and it was solved by removing the volume associated with the container in @brendan-rius If you just need the data saved in the volume (and you don't have anything else stored there), you should be able to run your postgres container (see the "... or via psql" section here) manually, dump your database, remove the volume, recreate everything, and import the database again. |
is there an easy way to just set all listen addresses so my code can access postgres? My code isnt copied into the image in development mode. |
@ekimia, what do you mean? If you have any shell scripts in If you are talking about accessing postgres from another container, then your code will have to wait for postgres to be ready, after it has done its initialization and run through any |
I feel like the original issue here has been solved. If you are still having trouble getting |
I just ran into this problem. I feel the initdb scripts will only run when the volume is first created should be made clear in the image description here. |
I'm having trouble writing a script to /docker-entrypoint-initdb.d/ and having Docker run it from /docker-entrypoint.sh.
cat
ing the script and verifying this is the expected behavior.pg_hba.conf
. I double checked this by verifying the mtime ofpg_hba.conf
- it wasn't touched or overwritten after my script ran. I also tried having my scripttouch
various files to just verify that it ran, with no success.I'm at a loss for how to continue debugging this; I placed a file in the place that it's supposed to go, verified that the script runner that starts postgres should run it, and verified that the script does what I want, and I don't see any output (a changed pg_hba.conf, or even a simple file).
I'm running the newest version of everything; starting Docker inside of a Ubuntu Virtualbox being provisioned from Vagrant. I share one folder from the Docker container to the host VM - the data folder containing pg_hba.conf.
Would appreciate your help!
Kevin
The text was updated successfully, but these errors were encountered: