How to use your own Docker image for your builds

Question from a user:

Any idea why I can’t mount the Gradle cache directory into the an openjdk image?
It seems to works just fine on my laptop ( docker run ... --volume ${HOME}/.gradle/:/root/.gradle ...)

Answer:

The thing is, because your build is already running in Docker (in a docker container), you can only share dirs between/through containers which are mounted as a volume from the host into the base Docker container (the one your build is running in).

The only one right now is (on the Android/Linux/Docker stacks): /bitrise

This means that if you share ${HOME}/.gradle/:/root/.gradle as a volume that won’t share the volume from the build’s container, that will share it from the host, where gradle is not installed (the only thing installed on the host is docker).

​So, if you want to share anything as a volume from your build into a container which is started by your build (e.g. with a docker run) you should share it from /bitrise. Your code by default is cloned into /bitrise/src, so you can share that directly if you want to. Otherwise, if you’d want to mount a volume into $HOME/.gradle inside the container you start, you should mount it from a /bitrise/ dir.

E.g. create a /bitrise/gradle-cache dir (or any dir under /bitrise) and then share it with --volume "/bitrise/gradle-cache:/root/.gradle" or similar.