Skip to content

Instantly share code, notes, and snippets.

@c-neto
Last active October 18, 2023 17:50
Show Gist options
  • Save c-neto/5d5379b798223f9a59f863a9304f5eb4 to your computer and use it in GitHub Desktop.
Save c-neto/5d5379b798223f9a59f863a9304f5eb4 to your computer and use it in GitHub Desktop.
Dockerfile Cheatsheet
# Stage for image creation for production
FROM maven:3-jdk-8 as builder
WORKDIR /app
# Setting the project's working directory for dependency installation
COPY application .
# Installing dependencies
RUN mvn -DskipTests=true clean
RUN mvn -DskipTests install
# Creating the "/app-jar-output" directory and copying the ".jar" file of this project with included dependencies
RUN mkdir /app-jar-output
RUN cp /app/target/*with-dependencies.jar /app-jar-output
# Stage for image creation for production
FROM openjdk:8-jre-slim-buster
# Setting the project's working directory
WORKDIR /app
# Fixing timezone (tzdata) for the container and upgrading to update the Java, which in turn updates its internal timezone. It's not ideal, but it resolves the issue.
RUN apt-get update -y &&\
apt-get --only-upgrade install tzdata -y
# apt-get install tzdata-java -y
# Copying the ".jar" file from the builder stage of the application
COPY --from=builder /app-jar-output/ .
# Running the application. The "*" is adopted to allow reusability of this Dockerfile in other applications since no fixed values are provided.
CMD /usr/local/openjdk-8/bin/java $JAVA_OPTS -jar $(ls *.jar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment