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.