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"
CodePudding user response:
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"]