Commit
·
77a2880
1
Parent(s):
79becd2
create proper role for postgres user and run
Browse files- Dockerfile +5 -1
- docker-entrypoint-wrapper.sh +15 -5
Dockerfile
CHANGED
@@ -5,7 +5,11 @@ USER root
|
|
5 |
# Install PostgreSQL and necessary dependencies
|
6 |
RUN apk update && apk add --no-cache \
|
7 |
postgresql \
|
8 |
-
postgresql-contrib
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Set up environment variables
|
11 |
ENV DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
|
|
|
5 |
# Install PostgreSQL and necessary dependencies
|
6 |
RUN apk update && apk add --no-cache \
|
7 |
postgresql \
|
8 |
+
postgresql-contrib \
|
9 |
+
shadow
|
10 |
+
|
11 |
+
# Create postgres user and group
|
12 |
+
RUN addgroup -S postgres && adduser -S -G postgres postgres
|
13 |
|
14 |
# Set up environment variables
|
15 |
ENV DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
|
docker-entrypoint-wrapper.sh
CHANGED
@@ -7,17 +7,27 @@ chmod 0755 /data/postgresql/run
|
|
7 |
|
8 |
# Initialize PostgreSQL if not already initialized
|
9 |
if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
fi
|
12 |
|
|
|
|
|
|
|
13 |
# Start PostgreSQL with the persistent directories
|
14 |
-
pg_ctl -D /data/postgresql/data -o
|
15 |
|
16 |
-
# Create database
|
17 |
-
|
|
|
|
|
18 |
|
19 |
# Wait for PostgreSQL to be ready
|
20 |
-
until pg_isready -h /data/postgresql/run; do
|
21 |
echo "Waiting for PostgreSQL to be ready..."
|
22 |
sleep 1
|
23 |
done
|
|
|
7 |
|
8 |
# Initialize PostgreSQL if not already initialized
|
9 |
if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then
|
10 |
+
# Initialize as postgres user
|
11 |
+
su postgres -c "initdb -D /data/postgresql/data"
|
12 |
+
|
13 |
+
# Modify pg_hba.conf to allow local connections
|
14 |
+
echo "local all all trust" > /data/postgresql/data/pg_hba.conf
|
15 |
+
echo "host all all 127.0.0.1/32 trust" >> /data/postgresql/data/pg_hba.conf
|
16 |
fi
|
17 |
|
18 |
+
# Ensure proper ownership
|
19 |
+
chown -R postgres:postgres /data/postgresql/data /data/postgresql/run
|
20 |
+
|
21 |
# Start PostgreSQL with the persistent directories
|
22 |
+
su postgres -c "pg_ctl -D /data/postgresql/data -o '-c listen_addresses=*' -o '-c unix_socket_directories=/data/postgresql/run' start"
|
23 |
|
24 |
+
# Create database and roles
|
25 |
+
su postgres -c "createuser -s postgres" || true
|
26 |
+
su postgres -c "createuser -s node" || true
|
27 |
+
su postgres -c "createdb -U postgres postgres" || true
|
28 |
|
29 |
# Wait for PostgreSQL to be ready
|
30 |
+
until su postgres -c "pg_isready -h /data/postgresql/run"; do
|
31 |
echo "Waiting for PostgreSQL to be ready..."
|
32 |
sleep 1
|
33 |
done
|