Update Dockerfile
Browse files- Dockerfile +10 -1
Dockerfile
CHANGED
@@ -6,11 +6,20 @@ ENV POSTGRES_DB=mydb
|
|
6 |
ENV POSTGRES_USER=myuser
|
7 |
ENV POSTGRES_PASSWORD=mypassword
|
8 |
|
9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
COPY init.sql /docker-entrypoint-initdb.d/
|
11 |
|
12 |
# Expose the default PostgreSQL port
|
13 |
EXPOSE 5432
|
14 |
|
|
|
|
|
|
|
15 |
# Start the PostgreSQL server when the container is launched
|
16 |
CMD ["postgres"]
|
|
|
6 |
ENV POSTGRES_USER=myuser
|
7 |
ENV POSTGRES_PASSWORD=mypassword
|
8 |
|
9 |
+
# Create a custom user and group for PostgreSQL
|
10 |
+
RUN groupadd -r postgres && useradd -r -g postgres postgres
|
11 |
+
|
12 |
+
# Set the ownership of the data directory
|
13 |
+
RUN mkdir -p /var/lib/postgresql/data && chown -R postgres:postgres /var/lib/postgresql/data
|
14 |
+
|
15 |
+
# Copy the init.sql file to the container
|
16 |
COPY init.sql /docker-entrypoint-initdb.d/
|
17 |
|
18 |
# Expose the default PostgreSQL port
|
19 |
EXPOSE 5432
|
20 |
|
21 |
+
# Run the PostgreSQL process as the custom user
|
22 |
+
USER postgres
|
23 |
+
|
24 |
# Start the PostgreSQL server when the container is launched
|
25 |
CMD ["postgres"]
|