Comments (21)
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.
from postgres.
I hit this problem - the issue is that the script is only run if there is no postgres data directory ;)
if [ -z "$(ls -A "$PGDATA")" ]; then
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
from postgres.
@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. docker-compose rm -v
should get rid of all the containers and their volumes if you want to start fresh on the database.
from postgres.
Any ETA on when we would be able to easily re-launch the init script (via a command maybe?), without removing the volumes?
from postgres.
Random debug thought: is the script executable in the container, maybe also ownership?
from postgres.
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
from postgres.
from postgres.
sometime the scripts could be used to perform update operations on the existing data.
for example updating an extension on all affected dbs.
It would be nice to have a base install scripts folder and an update scripts one
from postgres.
I hit this problem - the issue is that the script is only run if there is no postgres data directory ;)
if [ -z "$(ls -A "$PGDATA")" ]; then
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
I agree. The current approach makes it extremely hard to supply your own postgresql.conf
with a Dockerfile
that uses the official postgres image as base.
from postgres.
@jayfk, #72 should fix that part.
from postgres.
I too met this problem and have been trying to debug it for a week already.
my .sh scripts in docker-entrypoint-init.d/ never run.
I tryed extending Dockerfile from 9.4 image, and also I tryed building it myself from a copy of the original Dockerfile and docker-entrypoint.sh. It seems to be that the docker-entrypoint.sh never gets into the
if [ "$1" = 'postgres' ]; then
condition on line 17 of the script.
I ran out of ideas. Any help on this ?
from postgres.
@danwyry, what are you running? Any information you can give to help us reproduce the issue?
from postgres.
Sure, this is what I tryied so far:
I downloaded 9.4's Dockerfile and docker-entrypoint.sh to a directory on my computer
I added the functions detailed below to docker-entrypoint.sh and called them right after the set_listen_address '*' function is called.
on my docker-compose.yml I put :
build: my_postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes_from:
- data
ports:
- "5434:5432"
being 'my_postgres' the directory name under which y located the Dockerfile and entrypoint.
I ran docker-compose build.
It ran with no errors, but postgresql.conf.
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)
if [ "$1" = 'postgres' ]; then
These are the functions I added that configure some settings on postgresql.conf (I already tested them on their own and they work ok). :
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"
}
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:
FROM postgres:9.4
COPY docker-entrypoint-initdb.d/settings_postgres_conf.sh /docker-entrypoint-initdb.d/settings_postgres_conf.sh
RUN chmod 0755 /docker-entrypoint-initdb.d/settings_postgres_conf.sh
ENV PGDATA /var/lib/postgresql/data
VOLUME /var/lib/postgresql/data
But it won't work either.
from postgres.
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
from postgres.
would you mind trying it within a docker-compose configuration to see if maybe that's making any difference?
from postgres.
Hi @danwyry did you ever get your scripts running? I am having the same issue using docker-compose
from postgres.
nope, couldn't do it. But I stopped trying after a while
from postgres.
I had this exact same issue and it was solved by removing the volume associated with the container in docker-compose.yml
.
@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.
from postgres.
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.
from postgres.
@ekimia, what do you mean? If you have any shell scripts in /docker-entrypoint-initdb.d/
then they can access postgres via localhost
.
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 initdb
scripts.
from postgres.
I feel like the original issue here has been solved. If you are still having trouble getting /docker-entrypoint-initdb.d/
scripts to run, please open a new issue with as much information as possible.
from postgres.
Related Issues (20)
- Skip postgres restart on first run HOT 1
- Reproducible SIGSEGV in query HOT 1
- Separating config using PGDATA does not seem to behave as described in the docs HOT 12
- Upgrade older images to OCI Format or Docker Image manifest v2, schema 2 HOT 3
- Add a HEALTHCHECK to the images HOT 7
- include_dirs env var HOT 4
- Add "build from github.com/postgres/postgres" variation HOT 2
- PostgreSQL 17beta1 HOT 3
- CVE-2023-24538 CVE-2023-24540 HOT 2
- Use of GOSU introduces critical CVEs HOT 2
- PostgreSQL error ( log Docker) HOT 1
- Issue of working with pgsql in my vps machine with easypanel
- Nurlanhajizada
- Please help, I have persisted it, but the table and data are not restored after restarting the container. HOT 1
- please add a Container shell access and viewing MySQL logs directly HOT 3
- associate --user id with the internal postgres user id HOT 13
- Kill a postgres container immediately HOT 5
- Remove gosu HOT 3
- Log syslog to Docker logs command
- Security issues in latest postgres image HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postgres.