Installing and using Gradle in a docker image/container

Tags: , , , ,

I am getting this strange error at the end of the process of creating a docker image from a Dockerfile:

/bin/sh: 1: gradle: not found
INFO[0003] The command [/bin/sh -c gradle test jar] returned a non-zero code: 127

The relevant part of the Dockerfile:

FROM debian:jessie
RUN curl -L -o
RUN apt-get install -y unzip
RUN unzip
RUN echo 'export GRADLE_HOME=/app/gradle-2.4' >> $HOME/.bashrc
RUN echo 'export PATH=$PATH:$GRADLE_HOME/bin' >> $HOME/.bashrc
RUN /bin/bash -c "source $HOME/.bashrc"
RUN gradle test jar

The command I am using is: docker build -t java_i .

The strange thing is that if:

  • I run a container from the previous image commenting out RUN gradle test jar (command: docker run -d -p 9093:8080 -p 9094:8081 --name java_c -i -t java_i),
  • then I log into that container (command: docker exec -it java_c bash),
  • then I manually check the gradle environment variables finding them,
  • then I manually run that commented out command from within the running container (gradle test jar):

I eventually get the expected output (the compiled java code in the build folder).

I am using Docker version 1.6.2


I solved the problem using the ENV docker instructions (link to the documentation).

ENV GRADLE_HOME=/app/gradle-2.4

Source: stackoverflow