Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
Updated comments.
  • Loading branch information
nhkhai committed May 3, 2024
1 parent 0c075a1 commit f0015a3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ RUN ./mvnw clean install -DskipTests
# The base image to package. This is a multi-stage build using a new context.
FROM eclipse-temurin:21-jdk-jammy

# Setup a non-root user with user privileges instead of root privileges.
# RUN adduser -D myuser
# RUN addgroup usergroup; adduser --ingroup usergroup --disabled-password myuser;

# Install PostgreSQL and change PostgreSQL authentication to trust.
# Install the PostgreSQL package.
# Install the PostgreSQL package.
RUN apt-get update && apt-get install -y postgresql

# As a security best practice, switch to a non-root user with user privileges instead of root privileges.
# The USER Dockerfile instruction sets the preferred user name (or UID) and optionally the user group (or GID) while running the image — and for any subsequent RUN, CMD, or ENTRYPOINT instructions.
# Change the user to the PostgreSQL user.
# Change the user to the PostgreSQL user.
USER postgres

# Start the PostgreSQL service and create a new database used by the application, then change the PostgreSQL authentication method to trust and restart the PostgreSQL service.
Expand All @@ -55,10 +52,10 @@ EXPOSE $PORT
# Copy the Jar file generated from the builder context into the Docker image.
# Docker uses caching to speed up builds by reusing layers from previous builds.
# To take advantage of caching, you should order your Dockerfile instructions so that the ones that change frequently are placed towards the end of the file.
# For example, if you’re copying files into the image, you should do that at the end of the Dockerfile.
# For example, if you’re copying files into the image, you should do that at the end of the Dockerfile.
COPY --from=builder /opt/app/target/*.jar /opt/app/*.jar

# Set the default command to run the Java application.
# The ENTRYPOINT instruction specifies the command that should be run. The CMD instruction provides default arguments to the ENTRYPOINT command.
# Start the PostgreSQL service, wait for it to start, then run the Java application via its Jar file.
# Start the PostgreSQL service, then wait for it to start by checking with pg_isready (a utility specifically designed for checking if PostgreSQL is ready to accept connections). Once started, run the Java application via its Jar file.
ENTRYPOINT service postgresql start && while ! pg_isready -h localhost -p 5432; do sleep 1; done && java -jar /opt/app/*.jar

0 comments on commit f0015a3

Please sign in to comment.