OpenJDK Container / OpenJDK Docker Image download and installation.

OpenJDK Docker image

image courtesy - https://hub.docker.com/_/openjdk



Quick guide to download and install OpenJDK docker image.


What is OpenJDK


OpenJDK is the short form of Open Java Development Kit similar to Oracle's Java Development Kit used to develop Java Applications. Main difference between Oracle JDK and OpenJDK is that OpenJDK is free for all while Oracle Java Development Kit or Oracle JDK requires commercial license. For more details refer openjdk vs oracle jdk


If you want to know more about OpenJDK, you can go through Open Java Development Kit Quick guide.


Note: To uninstall previously installed OpenJDK please refer Uninstall OpenJDK Windows



Step #1: Download


There are many OpenJDK vendors out there in the market ( here is the OpenJDK Vendors List ), you can download OpenJDK from AdoptOpenJDK, Redhat OpenJDK, Zulu OpenJDK or from Community OpenJDK.

Below are the steps to download and install Community OpenJDK. If you would like to install OpenJDK from other vendors please refer :


OpenJDK Docker Image



We can use the openjdk docker image as both the build and runtime environment. We can compile and run our project simply by adding below lines in the Docker file.



Configure Docker file.

			
FROM openjdk:11
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Main.java
CMD ["java", "Main"]

			

Run and build the Docker image:


$ docker build -t my-java-app .
$ docker run -it --rm --name my-running-app my-java-app

Compile your app inside the Docker container


if you dont want to run your app inside a container and would like to compile your app, you can run the below commands:


$ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp openjdk:11 javac Main.java

This will add your current directory as a volume to the container, set the working directory to the volume, and run the command javac Main.java which will tell Java to compile the code in Main.java and output the Java class file to Main.class.


Congratulations !!! Now you have configured OpenJDK Docker image Successfully. For more info, please refer OpenJDK Docker Image

OpenJDK Known Issues


Note: Here is the list of OpenJDK known-issues OpenJDK Known Issues



x