Public | Automated Build

Last pushed: 7 months ago
Short Description
Gradle Container to Facilitate Developing Java/Groovy projects
Full Description

Gradle Executable Container

This Docker image includes OpenJDK 8 and Gradle 3.3 configured with Gradle as the entrypoint.


By default, running this image without any command will run gradle -version in the /usr/bin/app directory.

Doing Something Actually Useful

To run something more interesting, say gradle clean war, you should mount your project root in /app. For example, you can run the following to create a deployable web archive.

docker run --rm -v /path/to/your/project:/usr/bin/app:rw niaquinto/gradle clean war


Of course, you can use any command here, including those dependent on plugins. For example, if you project includes the Jetty plugin (by including apply plugin: 'jetty' in its build.gradle) you can run the following command to start an instance of Jetty running a WAR of your application on port 8080 on the host.

docker run --rm -p 8080:8080 -v /path/to/your/project:/usr/bin/app:rw niaquinto/gradle jettyRunWar

Changing the Default Behavior

Say you want gradle clean war to run if you launch the container without any options. To do that, just make a new Dockerfile like the following:

FROM niaquinto/gradle

# Set your default behavior
ENTRYPOINT ["gradle"]
CMD ["clean", "war"]


To cache your dependencies, you must mount the /root/.gradle/caches directory to your host:

docker run --rm -v /path/to/your/project:/usr/bin/app:rw niaquinto/gradle resolveDependencies

If you are using this image as a base container, these caches are retained between layers. So, you can decrease your image build times by running resolveDependencies in a separate layer, allowing Docker to only rebuild it if your project changes. (See issue 13)

FROM niaquinto/gradle

COPY build.gradle .
RUN gradle resolveDependencies
COPY . .
RUN gradle build

Conversely if you only need to built artifact and want a smaller image size, you should removing the caches after building. You must do this within the same image that you download the dependencies and build. (Again, see issue 13)

FROM niaquinto/gradle

RUN gradle build && rm -rf ${HOME}/.gradle/caches

# ...

Get the Image

To build this image yourself, run...

docker build

Or, you can pull the image from the central docker repository by using...

docker pull niaquinto/gradle
Docker Pull Command
Source Repository

Comments (5)
a year ago

It works for me

2 years ago

the latest version not work

2 years ago

In the 2.6 version image, which is latest as of 2015/18/08, the WORKDIR changed to /usr/src/app to be more in-line with the onbuild versions of standard programming language docker images. (see this GitHub issue)

2 years ago

The latest image does not work. When i run

docker run --rm -v /path/to/your/project:/app:rw niaquinto/gradle clean war

I get task not found. If i change it to
docker run --rm -v /path/to/your/project:/app:rw niaquinto/gradle:2.5 clean war

It works.

2 years ago

I'm getting this error when building Android project

* What went wrong:
A problem occurred configuring project ':app'.
> The SDK directory '/home/gkiko/Android/Sdk' does not exist.

Is it possible to reference my Android sdk from your container?