Low Orbit Flux Logo 2 D

Docker How To Run Java Jar

Running a Java jar file inside a Docker container is easier than you might think. We are going to show you how you can define an image and run a container based on that image using a jar file as the main application or command.

We’re actually kind of cheating by using a base image that already has Java installed.

You can define an image using a Dockerfile like this:

FROM anapsix/alpine-java
COPY test1.jar /data/test1.jar
CMD ["java","-jar","/data/test1.jar"]

Build it like this:

docker build -t my-image1 .

Run it like this:

docker run -d my-image1