Distroless - Apache Tomcat - Errors out when running

34 views
Skip to first unread message

Arvind

unread,
Apr 9, 2024, 6:25:43 PMApr 9
to Distroless Users
Hello Everyone,

I'm trying to use Distroless as my base image and copy the apache tomcat application server package to the docker image and did all the necessary steps to create a docker image
which will deploy the war file to the tomcat webapps directory and start the tomcat server by using the following command

# Set the command to start Tomcat
CMD ["java", "-cp", "/usr/local/tomcat/bin/bootstrap.jar", "org.apache.catalina.startup.Bootstrap", "start"]

I was successfull in building the docker image, but when i ran the built image, i see an error saying "Error: Unable to access jarfile java".

With this error, i even tried changing the permission on the bootstrap.jar and copied the same to the apache tomcat bin directory in the dockerfile. After that
tried building and running the updated docker image, i got the same error as before.

Here is the Dockerfile which i have tried

# Use Distroless base image
FROM gcr.io/distroless/java:11

# Set the working directory in the container
WORKDIR /usr/local/tomcat

# Copy Tomcat files into the image
ADD apache-tomcat-9.0.87.tar.gz /usr/local/tomcat

# Copy the Tomcat files into the image
#COPY bootstrap.jar /usr/local/tomcat/bin/bootstrap.jar

COPY --chown=nonroot:nonroot bootstrap.jar /usr/local/tomcat/bin/bootstrap.jar

COPY app1.war /usr/local/tomcat/webapps/

ENV TOMCAT_MAJOR=9 \
    TOMCAT_VERSION=9.0.87 \
    CATALINA_HOME=/usr/local/tomcat \
JAVA_OPTS="-Xms1G -Xmx1G"

# Expose Tomcat port
EXPOSE 8080

# Set the command to start Tomcat
CMD ["java", "-cp", "/usr/local/tomcat/bin/bootstrap.jar",  "org.apache.catalina.startup.Bootstrap", "start"]


Does anyone faced this issue before ?  Appreciate any suggestion on this issue.


Thanks,
Arvind

Natsuki Ikeguchi

unread,
Apr 9, 2024, 7:18:30 PMApr 9
to Distroless Users
Hi Arvind,

distroless/java images have the default entrypoint ['java', '-jar'] [^1]. Docker images can have an entrypoint and a command, which will be run as [entrypoint] [command]; you are actually trying to run 'java -jar java -jar'.

To resolve this, you can remove 'java' '-jar' from the CMD line, or use ENTRYPOINT instead of CMD. For details about ENTRYPOINT and CMD directives, see the Docker official documentation [^2].

Regards,
Natsuki


[^1]: https://github.com/GoogleContainerTools/distroless/blob/863ecbfd66dc684333a8c07c2eebd705171399a8/java/BUILD#L197
[^2]: https://docs.docker.com/reference/dockerfile/#entrypoint

Arvind

unread,
Apr 10, 2024, 2:52:31 AMApr 10
to Distroless Users
Thank you Natsuki. It helped me move further on this. 

Thanks,
Arvind
Reply all
Reply to author
Forward
0 new messages