1

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.