Container images for the Microsoft Build of OpenJDK
This article provides information on the available container images for the Microsoft Build of OpenJDK.
Linux-based images
We currently provide Linux-based container images for both Ubuntu 20.04 and CBL-D (a Debian-based Linux distribution built from source by Microsoft). The images are published in the Microsoft Container Registry located at mcr.microsoft.com/openjdk/jdk.
To pull the latest image for a specific tag, use the following command:
docker pull mcr.microsoft.com/openjdk/jdk:<tag>
The following table shows the tag to use for your Linux distribution and JDK version.
| Base OS | JDK 11 | JDK 16 | JDK 17 |
|---|---|---|---|
| Ubuntu 20.04 | 11-ubuntu |
16-ubuntu |
17-ubuntu |
| CBL Mariner | 11-mariner |
16-mariner |
17-mariner |
| CBL-D Quinault | 11-cbld |
16-cbld |
17-cbld |
To use these images, create a Dockerfile with the following contents:
# Example using MS Build of OpenJDK image directly
FROM mcr.microsoft.com/openjdk/jdk:17-ubuntu
# Continue with your application deployment
RUN mkdir /opt/app
COPY japp.jar /opt/app
CMD ["java", "-jar", "/opt/app/japp.jar"]
Use a different Base OS image
If you prefer an OS base image distribution that we don't provide an image for, you can copy the JDK using the COPY --from instruction in a Dockerfile, similar to the following example:
# Example using MS Build of OpenJDK image with a different base image
FROM debian:buster-slim
ENV LANG en_US.UTF-8
ENV JAVA_HOME /usr/lib/jvm/msopenjdk-17-amd64
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=mcr.microsoft.com/openjdk/jdk:17-ubuntu $JAVA_HOME $JAVA_HOME
# Continue with your application deployment
RUN mkdir /opt/app
COPY japp.jar /opt/app
CMD ["java", "-jar", "/opt/app/japp.jar"]
You can also install the JDK using either yum or apt-get, or simply extracting a tar.gz file and configuring JAVA_HOME accordingly. Read more.
Create a custom Java runtime
To create a custom Java runtime image, use a Dockerfile similar to the following example:
# Example of custom Java runtime using jlink in a multi-stage container build
FROM mcr.microsoft.com/openjdk/jdk:17-ubuntu as runtime-build
# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink \
--add-modules java.base \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime
# Define your base image. You may use any base OS and version of your choice.
FROM debian:buster-slim
ENV LANG en_US.UTF-8
ENV JAVA_HOME /usr/lib/jvm/msopenjdk-17-amd64
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=runtime-build /javaruntime $JAVA_HOME
# Continue with your application deployment
RUN mkdir /opt/app
COPY japp.jar /opt/app
CMD ["java", "-jar", "/opt/app/japp.jar"]
For more information on creating custom Java runtimes, see Java Runtimes with jlink
Default locale
The images for Microsoft Build of OpenJDK are configured by default with the en_US.UTF-8 locale. If you want to use a different locale, or a different base image as described previously, you'll need to manually configure environment variables in your own Dockerfile, and make sure the locale you want is installed.
For example, to use the pt_BR.UTF-8 locale on an Ubuntu-based image, you can add the following lines to your Dockerfile:
...
USER root
RUN apt-get update
RUN apt-get install -y locales
RUN sed -i '/pt_BR.UTF-8/s/^# //g' /etc/locale.gen
RUN locale-gen
ENV LANG pt_BR.UTF-8
ENV LANGUAGE pt_BR:pt
ENV LC_ALL pt_BR.UTF-8
...
This Dockerfile is provided as an example, and is not meant to suggest the most optimal configurations.
Stay on older minor versions
Microsoft Build of OpenJDK container images are only available under the tags listed previously. We don't publish tags for minor versions, and the major version tags always have the latest minor version to ensure that developers will always have the latest update for any given major version.
These base images use the underlying package manager mechanism of the Linux distributions to install the JDK package. Therefore, to stay on a particular version, you'll need to use tools such as apt-get or yum to install the specific minor version of the JDK.
To install specific versions on different base OS images, for example debian:buster-slim, you can use the same approach either in the first stage of a muli-stage Docker build, or as part of a traditional Linux package installation flow. For more information, see the Install on Ubuntu 18.04+ section of Install the Microsoft Build of OpenJDK.
For CBL-Mariner and other OS images based on RPM/yum, see the details provided later in this article.
For Ubuntu, CBL-D and other Debian-based images, you can display all available minor versions published in the Microsoft Linux repositories, as shown in the following Bash example showing commands and output. The commands shown here assume the Microsoft Linux repo is configured, as described at Install on Ubuntu 18.04+.
$ docker run -ti --rm mcr.microsoft.com/openjdk/jdk:11-ubuntu
root@c60eacd7dd7d:/# apt-get update
...
root@c60eacd7dd7d:/# apt-cache madison msopenjdk-11
msopenjdk-11 | 11.0.12+7-1 | https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
msopenjdk-11 | 11.0.11+9-1 | https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
msopenjdk-11 | 11.0.10+9-1 | https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
This Bash example shows how to have your image revert msopenjdk-11 to an older version, say 11.0.11+9-1:
root@dd24eca5bdb3:/# java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Microsoft-25199 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Microsoft-25199 (build 11.0.12+7, mixed mode)
root@dd24eca5bdb3:/# apt-cache madison msopenjdk-11
msopenjdk-11 | 11.0.13+8-LTS-1 | https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
msopenjdk-11 | 11.0.12+7-1 | https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
msopenjdk-11 | 11.0.11+9-1 | https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
msopenjdk-11 | 11.0.10+9-1 | https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages
root@dd24eca5bdb3:/# apt-get -y install -y --allow-downgrades msopenjdk-11=11.0.11+9-1
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be DOWNGRADED:
msopenjdk-11
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 17 not upgraded.
Need to get 193 MB of archives.
After this operation, 353 kB disk space will be freed.
Get:1 https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 msopenjdk-11 amd64 11.0.11+9-1 [193 MB]
Fetched 193 MB in 6s (30.9 MB/s)
debconf: delaying package configuration, since apt-utils is not installed
dpkg: warning: downgrading msopenjdk-11 from 11.0.12+7-1 to 11.0.11+9-1
(Reading database ... 5936 files and directories currently installed.)
Preparing to unpack .../msopenjdk-11_11.0.11+9-1_amd64.deb ...
Unpacking msopenjdk-11 (11.0.11+9-1) over (11.0.12+7-1) ...
Setting up msopenjdk-11 (11.0.11+9-1) ...
To do the same thing in your Dockerfile, use the following commands:
FROM mcr.microsoft.com/openjdk/jdk:11-ubuntu
...
RUN apt-get update && \
apt-get install -y --allow-downgrades msopenjdk-11=11.0.11+9-1
...
This Bash example uses CBL-Mariner based images:
root [ / ]# java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Microsoft-25199 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Microsoft-25199 (build 11.0.12+7, mixed mode)
root [ / ]# yum update
...
root [ / ]# yum list msopenjdk-11
Loaded plugin: tdnfrepogpgcheck
msopenjdk-11.x86_64 11.0.12+7-1 @System
msopenjdk-11.x86_64 11.0.10+9-1 packages-microsoft-com-prod
msopenjdk-11.x86_64 11.0.11+9-1 packages-microsoft-com-prod
msopenjdk-11.x86_64 11.0.12+7-1 packages-microsoft-com-prod
root [ / ]# yum install -y --nogpgcheck msopenjdk-11-11.0.10+9-1
Loaded plugin: tdnfrepogpgcheck
Downgrading:
msopenjdk-11 x86_64 11.0.10+9-1 packages-microsoft-com-prod 308.38M 323358496
Total installed size: 308.38M 323358496
Downloading:
Testing transaction
Running transaction
Installing/Updating: msopenjdk-11-11.0.10+9-1.x86_64
Removing: msopenjdk-11-11.0.12+7-1.x86_64
Complete!
To do the same thing in your Dockerfile, use the following commands:
FROM mcr.microsoft.com/openjdk/jdk:11-mariner
...
RUN yum update && \
yum install -y --nogpgcheck msopenjdk-11-11.0.10+9-1
...
Windows-based images
We currently do not provide Windows-based container images.
Provide feedback on the Microsoft Build of OpenJDK
Send us your comments, thoughts, and ideas to help us improve the Microsoft Build of OpenJDK. Visit our OpenJDK discussions page on GitHub to send us your feedback.
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.