Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got error "xargs is not available" when trying to run a docker image

Tags:

docker

gradle

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"

like image 305
XintongTheCoder Avatar asked Nov 27 '25 06:11

XintongTheCoder


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

RUN microdnf install findutils

For the Alpine based images the command would be:

RUN apk update && apk add findutils

Your Dockerfile should be

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
RUN microdnf install findutils
COPY --from=builder /home/gradle/src/build/install/app/ /app/
WORKDIR /app

CMD ["bin/app"]
like image 153
Tolis Gerodimos Avatar answered Nov 28 '25 20:11

Tolis Gerodimos


TL;DR: openjdk Docker images version >= 14 don't include xargs. Use a non-deprecated docker image instead


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 message xargs 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):

The xargs utility was usually found only in System V-based systems; BSD systems included an apply utility that provided functionality similar to xargs -n number. The SVID lists xargs as a software development extension. This volume of POSIX.1-2017 does not share the view that it is used only for development, and therefore it is not optional.

However openjdk Docker images version >= 14 don't include xargs. 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 have xargs installed in this comment on the issue. At the time of writing, apart from the deprecated openjdk images, only ubi9-minimal variants of Eclipse Temurin images don't have xargs. 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 install xargs as part of the findutils package using the package manager of the image, as described in the other answer.

like image 37
Joffrey Avatar answered Nov 28 '25 22:11

Joffrey