We support three (four) ways of running your app:
- A fat jar called
app.jar
- An exploded war
- Custom run script
Create a Dockerfile
containing:
The simplest way of running your app is to create a far jar and copy it into your container as app.jar
.
Since the default working directory is /app
, there's no need to specify the path.
FROM ghcr.io/navikt/fp-baseimages/java:<version>
COPY target/my-awesome.jar app.jar
If you want to use another name for your file, set it using APP_JAR
:
FROM ghcr.io/navikt/fp-baseimages/java:<version>
ENV APP_JAR=my-awesome.jar
COPY target/my-awesome.jar .
Supply the name of your main class as an environment variable called
MAIN_CLASS
if the name of your main class is not the default "Main".
Custom runtime options may be specified using the environment variable JAVA_OPTS
.
You can add custom behavior to your container by copying .sh
files
to the /init-scripts
dir. The files are sourced which means that
you can export environment variables or extend the existing ones like JAVA_OPTS
.
If none of the other ways of running an app suits you, you can create a custom run-script
at /run-java.sh
. Be sure to include the different environment variables
JAVA_OPTS
, DEFAULT_JVM_OPTS
and RUNTIME_OPTS
to get all the goodies
that the baseimage sets up for you.
# copy into the container as /run-java.sh
exec java ${DEFAULT_JVM_OPTS} ${JAVA_OPTS} -jar app.jar ${RUNTIME_OPTS} $@
We highly recommend that you write your app so that you don't need this feature.