Search code examples
javadockerkuberneteswildfly

Create docker image for Wildfly 27 with redhat open JDK 17


I am trying to build a docker image with Wildfly 27 and Redhat Openjdk 17, below is the docker file. i am keeping registry.access.redhat.com/ubi9/openjdk-17:1.18-1 as FROM

FROM registry.access.redhat.com/ubi8/openjdk-17-runtime:1.19-1

USER root
RUN mkdir -p /opt/jboss/

RUN curl -sS https://github.com/wildfly/wildfly/releases/download/27.0.1.Final/wildfly-27.0.1.Final.tar.gz
  
RUN echo "Downloaded JBoss"

# Extract Wildfly
COPY  wildfly-27.0.1.Final.tar.gz /opt/jboss
RUN tar -xzf jboss/wildfly-27.0.1.Final.tar.gz -C /opt/jboss

COPY  standalone.xml /opt/jboss/wildfly/standalone/configuration/

#FROM registry.access.redhat.com/ubi8/openjdk-17:1.19-1
#ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64

EXPOSE 86
EXPOSE 9443

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-c", "standalone.xml", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

Restult: enter image description here

when i tried to build this using docker build -t appName . , getting error as below

ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 8387d982-e13d-46e2-8bd8-0f262ea5ae6c::s2b234ci5jrua5fp6qqwgcjy7: "/java-17-openjdk-17.0.10.0.7-1.portable.jre.el.x86_64.tar.xz": not found

Docker Environment: Windows.

please suggest what is the right way to create image for Wildfly 27 with Redhat JDK 17


Solution

  • If your intention is to download the package wildfly-27.0.1.Final.tar.gz and unpack it under /opt/jboss, the following fixes need to be applied to the Dockerfile:

    • The base image need the gzip dependency to allow tar to uncompress the package: RUN microdnf install gzip
    • The download step with curl need to save the output on disk: RUN curl -L https://github.com/wildfly/wildfly/releases/download/27.0.1.Final/wildfly-27.0.1.Final.tar.gz -OJ
    • The copy step is useless since the unpack step will support it. By the way it uses the wrong COPY instruction unless the intention is to copy the package from the host and not the downloaded one: COPY wildfly-27.0.1.Final.tar.gz /opt/jboss
    • The uncompress step need to be adapt like so: RUN tar xzvf wildfly-27.0.1.Final.tar.gz -C /opt/jboss/

    At the end the Dockerfile can looks like this:

    FROM registry.access.redhat.com/ubi8/openjdk-17-runtime:1.19-1
    
    USER root
    RUN \
        microdnf install gzip \
        && curl -L https://github.com/wildfly/wildfly/releases/download/27.0.1.Final/wildfly-27.0.1.Final.tar.gz -OJ \
        && echo "Downloaded JBoss" \
        && tar -xzf wildfly-27.0.1.Final.tar.gz -C /opt/jboss \
        && mv /opt/jboss/wildfly-27.0.1.Final /opt/jboss/wildfly
    
    COPY  standalone.xml /opt/jboss/wildfly/standalone/configuration/
    
    #FROM registry.access.redhat.com/ubi8/openjdk-17:1.19-1
    #ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
    
    EXPOSE 86
    EXPOSE 9443
    
    CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-c", "standalone.xml", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]