How to prevent downloading of Gradle dependencies when doing docker run for gradle projects

Write these entries into your Dockerfile as follows:

RUN mkdir -p /root/.gradle
ENV HOME /root
VOLUME /root/.gradle

In your docker run command, you just need to amount your root .gradle folder from your machine like so:

docker run -v ~/.gradle:/root/.gradle imagename:tagname

The gradle dependencies will be downloaded the first time, and for subsequent gradle runs, it won’t download anymore.

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center