postgres / Dockerfile
bpandey23's picture
Update Dockerfile
d86b156 verified
raw
history blame
734 Bytes
# 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
# Create a custom user and group for PostgreSQL
RUN groupadd -r postgres && useradd -r -g postgres postgres
# 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"]