File size: 850 Bytes
9647270
 
 
 
 
 
 
 
6b37c94
 
 
d86b156
 
 
 
 
9647270
 
 
 
 
d86b156
 
 
9647270
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Use the official PostgreSQL image as the base image
FROM postgres:13

# Set the environment variables for the PostgreSQL database
ENV POSTGRES_DB=mydb
ENV POSTGRES_USER=myuser
ENV POSTGRES_PASSWORD=mypassword

# Check if the postgres user and group exist, and create them if not
RUN if ! id -g postgres > /dev/null 2>&1; then groupadd -r postgres; fi
RUN if ! id -u postgres > /dev/null 2>&1; then useradd -r -g postgres postgres; fi

# Set the ownership of the data directory
RUN mkdir -p /var/lib/postgresql/data && chown -R postgres:postgres /var/lib/postgresql/data

# Copy the init.sql file to the container
COPY init.sql /docker-entrypoint-initdb.d/

# Expose the default PostgreSQL port
EXPOSE 5432

# Run the PostgreSQL process as the custom user
USER postgres

# Start the PostgreSQL server when the container is launched
CMD ["postgres"]