IntelliJ IDEA
 
Get IntelliJ IDEA
You are viewing the documentation for an earlier version of IntelliJ IDEA.

Run a Java application in a Docker container

Last modified: 08 March 2021

Required plugins: Docker (bundled)

You can use Docker to run a Java application in a container with a specific runtime environment. This tutorial describes how to create a Dockerfile for running a simple Java application in a container with OpenJDK 8. It also shows how to create a Docker image with your application to share it with others.

The sample application consists of a single HelloWorld.java file, which prints Hello, World! to the console and exits. By default, IntelliJ IDEA compiles the output to the project directory under /out/production/HelloWorld, where HelloWorld is the name of the current module.

Sample Java application project

You can share the image with others, for example, to demonstrate exactly how your application is expected to run, without the need to install the necessary runtime (only Docker is required).