andrewrreed HF Staff commited on
Commit
4cea1d8
·
1 Parent(s): d0b21bc

run postgres as postgres user instaed of su

Browse files
Files changed (1) hide show
  1. Dockerfile +9 -5
Dockerfile CHANGED
@@ -23,13 +23,17 @@ ENV NEXTAUTH_URL=http://localhost:3000
23
  # Create a wrapper script that will start Postgres before running the original entrypoint
24
  COPY <<EOF /docker-entrypoint-wrapper.sh
25
  #!/bin/sh
26
- # Initialize PostgreSQL
27
- su postgres -c "initdb -D /var/lib/postgresql/data"
28
- su postgres -c "pg_ctl -D /var/lib/postgresql/data -l /var/log/postgresql/postgresql.log -o '-c listen_addresses=*' start"
29
- su postgres -c "createdb -U postgres postgres" || true
 
 
 
 
30
 
31
  # Wait for PostgreSQL to be ready
32
- while ! su postgres -c "pg_isready"; do
33
  echo "Waiting for PostgreSQL to be ready..."
34
  sleep 1
35
  done
 
23
  # Create a wrapper script that will start Postgres before running the original entrypoint
24
  COPY <<EOF /docker-entrypoint-wrapper.sh
25
  #!/bin/sh
26
+
27
+ # Switch to postgres user for database operations
28
+ chown -R postgres:postgres /var/lib/postgresql/data /run/postgresql
29
+
30
+ # Initialize and start PostgreSQL as postgres user
31
+ runuser -u postgres -- initdb -D /var/lib/postgresql/data
32
+ runuser -u postgres -- pg_ctl -D /var/lib/postgresql/data -l /var/log/postgresql/postgresql.log -o '-c listen_addresses=*' start
33
+ runuser -u postgres -- createdb -U postgres postgres || true
34
 
35
  # Wait for PostgreSQL to be ready
36
+ until runuser -u postgres -- pg_isready; do
37
  echo "Waiting for PostgreSQL to be ready..."
38
  sleep 1
39
  done