How to run gradle inside of docker

I want to make complex build with dependencies from npm, python etc repeatable and easy with docker without sacrificing any of the efficiency compared to running it outside of a container.

I wonder which communication protocol is used by gradle and gradle daemon? And will build cache be shared if I will mount ~/.gradle/ into container?