Dockerfile for Creating A UBI-based Docker Image and OpenJDK

I use UBI 8 as base images for basically almost every java deployment. It’s lightweight, freely redistributable, and easy to configure.

This is my simplified Dockerfile script, which consist of UBI8 and OpenJDK installation.


MAINTAINER Muhammad Edwin < emuhamma at redhat dot com >

# Some version information
LABEL io.k8s.description="Platform for running plain Java applications (fat-jar and flat classpath)" \
      io.k8s.display-name="My Simple Java Applications" \
      io.openshift.tags="builder,java" \
      org.jboss.deployments-dir="/deployments" \
      com.redhat.deployments-dir="/deployments" \"JAVA_DEBUG:false" \"JAVA_DEBUG_PORT:5005"

# Install Java runtime
RUN microdnf install java-11-openjdk-headless --nodocs \
 && microdnf install shadow-utils && microdnf clean all \
 && mkdir /deployments

# Add user & group
RUN groupadd jboss && useradd jboss -g jboss

# Use /dev/urandom to speed up startups & Add jboss user to the root group
RUN echo securerandom.source=file:/dev/urandom >> /usr/lib/jvm/jre/lib/security/ \
 && usermod -g root -G jboss jboss

# set working directory at /deployments
WORKDIR /deployments

# copy corresponding jar file
COPY demo.jar demo.jar

# Necessary to permit running with a randomised UID
RUN mkdir -p /deployments/data \
 && chmod -R "g+rwX" /deployments \
 && chown -R jboss:jboss /deployments \
 && chmod 664 /etc/passwd

# gives uid
USER 185

# run it
CMD ["java","-jar","demo.jar"]

1 Comment

Eric Ace

about 2 months ago

Hey - this helped me. Thanks!


Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked

:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)