Simple to use Gradle Plugin to build, tag and push Docker Images. Supports Multi-Module-Projects, build caching, Java 8 and runs on Gradle 6+ and 7+.
Apply the plugin:
plugins {
id 'com.github.jazzschmidt.gradle-docker-plugin' version '<version>'
}
All projects that have a
docker
directory will be configured with the docker tasks.
Suppose the following project structure:
- :root: project
- build.gradle
- :example: project
- docker/
- Dockerfile
- config.toml
- src/main/java
- ...
- build.gradle
- docker/
With the following build.gradle
:
// Project :root:
plugins {
id 'com.github.jazzschmidt.gradle-docker-plugin' version '1.0.1'
}
group 'com.example'
version '0.0.1'
// Define custom docker registries
dockerRegistry {
uploadTo("registry", "my-registry.com")
}
// Project :example:
plugins {
id 'java'
}
group 'com.example'
version '0.0.1'
dockerImage {
from(jar)
tag "nexus", "nexus.local/${project.name}" // Omit the version to use project version
tag "nexusLatest", "nexus.local/${project.name}:latest"
}
This will generate the following tasks in :example: project in the docker
group:
docker
- builds the Docker imagedockerAssemble
- assembles resources for the image inbuild/docker
dockerClean
- cleans the resources and all tagsdockerTag
- creates all tagsdockerTagRegistry
- tagsmy-registry.com/example:0.0.1
dockerTagNexus
- tagsnexus.local/example:0.0.1
dockerTagNexusLatest
- tagsnexus.local/example:latest
dockerPush
- pushes all tags
and tasks for pushing specific tags:
dockerPushRegistry
dockerPushNexus
dockerPushNexusLatest
Any file in the docker
directory will be used to assemble the Docker Image.
The plugin adds a dockerImage
extension, that can be used to add further
dependencies to the Docker build and define custom tags. As for the example
above, dockerAssemble
will create something like this:
- :example: project
- build/docker
- Dockerfile
- config.toml
- example-0.0.1.jar
- build/docker