Dockerfile
A Dockerfile is where you’ll estabilish the definitions used to build a container image. It uses three main keywords/commands:
-
FROM: where you’ll inform the base image used to build your own image
-
COPY: where you’ll add resources (files) to your image
-
CMD: where you’ll inform how to start the application
Sometimes people ask when to use ADD and when to use COPY. Both of them can be used to copy files from the source to destination, but:
|
Creating an application to be containerized
Let’s first create a simple Java application so we can containerize it.
mvn "io.quarkus:quarkus-maven-plugin:create" \
-DprojectGroupId="com.redhat.developers" \
-DprojectArtifactId="tutorial-app" \
-DprojectVersion="1.0-SNAPSHOT" \
-DclassName="HelloResource" \
-Dpath="hello"
cd tutorial-app
All the remaining parts of this tutorial assume that you’ll be working inside the project folder that was just created. In this case, tutorial-app .
|
To let this application be ready to be distributed, let’s package it:
mvn package
Building a Dockerfile
Create a file named Dockerfile.
cat <<EOF >Dockerfile
FROM registry.access.redhat.com/ubi8/openjdk-17
COPY target/quarkus-app/lib/ /deployments/lib/
COPY target/quarkus-app/quarkus-run.jar /deployments/app.jar
COPY target/quarkus-app/app/ /deployments/app/
COPY target/quarkus-app/quarkus/ /deployments/quarkus/
CMD ["java", "-jar", "/deployments/app.jar"]
EOF