I’m trying to run a hello word java application in docker. The application is produced by gradle init. I use gradle installDist to generate runnable file. I can run the runnable locally without any problem. But I got the error when I try to run from docker. Here is the docker file content:
FROM gradle:7.1.0-jdk11 AS builder
WORKDIR /home/gradle/src
COPY --chown=gradle:gradle . /home/gradle/src
RUN gradle installDist
FROM openjdk:17-oracle
COPY --from=builder /home/gradle/src/build/install/app/ /app/
WORKDIR /app
CMD ["bin/app"]
The docker file is placed in the same folder with build.gradle and the docker build command is ran from that folder. Build runs successfully. But as long as I click run in the docker GUI, the container fails immediately with error message "xargs is not available"
2
Answers
As the error describes,
xargs
is not available.Looking at your Dockerfile, the jdk image you use, is based on Oracle Linux
So you need to add the following line, which installs the required package
For the Alpine based images the command would be:
Your Dockerfile should be
Since Gradle version 7.5, an explicit check for
xargs
presence has been added to solve this issue, which is why you’re seeing the messagexargs is not available
when running either the Gradle wrapper script itself, or a start script for an application that was built using the Gradle Distribution Plugin.Note that it is quite rare that
xargs
is not present, because it’s part of the POSIX standard. See this part of xargs doc in POSIX.1-2017 (emphasis mine):However
openjdk
Docker images version >= 14 don’t includexargs
. That said, those images are deprecated and should not be used anymore. I tested many alternative JDK images and compiled a list of the ones that do havexargs
installed in this comment on the issue. At the time of writing, apart from the deprecatedopenjdk
images, onlyubi9-minimal
variants of Eclipse Temurin images don’t havexargs
. All other images I tested are OK.If you really want to use an image that doesn’t have
xargs
by default, you may of course installxargs
as part of thefindutils
package using the package manager of the image, as described in the other answer.