Dan Azoulay
Dan Azoulay

Reputation: 81

Docker image for executing gradle bootBuildImage command

I'm looking for a docker image to build my gradle project which also need a docker engine to execute gradle bootBuildImage command. Any recommandation ?

Thanks,

Dan

Upvotes: 1

Views: 1758

Answers (1)

Bjørn Vester
Bjørn Vester

Reputation: 7598

If you use the Gradle wrapper scripts (which you should), you can use any image you like as long as it has Java on it. OpenJDK is a good match.

If you don't use the wrapper scripts, you need to have an image with Gradle installed. The official Gradle image should do.

But I think what you are really asking is how to build a docker image inside a container. The bootBuildImage task doesn't need the local Docker cli tools, and only needs to connect to a daemon. That daemon could be running on a remote host, but you can also make it connect to your local host outside the container. To do this, mount the local docker socket.

Here is an example that mounts the current directory inside a container and builds a Docker image in it through the Spring Boot plugin for Gradle:

docker run --rm \
  -v gradle-cache:/home/gradle/.gradle \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$PWD":/home/gradle/project \
  -w /home/gradle/project \
  gradle:6.7.0-jdk11 \
  gradle --no-daemon bootBuildImage

Note that it persists the Gradle home directory in a volume, which means you can't run this command concurrently. Delete the volume when no longer needed with docker volume rm gradle-cache.

Also note that it executes the build as root.

Upvotes: 1

Related Questions