I have just released version 0.3 of my gradle-dockerfile-plugin. This is a Gradle plugin to build and push Docker images using an external Dockerfile. This means there is no need of inline configuration for Docker in the Gradle build file. The plugin is available through Maven Central and the Gradle Plugin Portal.


To use the plugin add a build script dependency to your Gradle build file:

buildscript {
    repositories { mavenCentral() }
    dependencies { classpath('org.sglahn:gradle-dockerfile-plugin:0.3') }
apply plugin: 'dockerfile'

or via the new plugin mechanism introduced in Gradle 2.1:

plugins {
  id "org.sglahn.gradle-dockerfile-plugin" version "0.3"

The plugin will add the following tasks to your project:

$ ./gradlew tasks
Docker tasks
dockerBuild - Builds a new image with a Dockerfile.
dockerPush - Pushes a docker image to a repository.

The dockerBuild task

The dockerBuild task will build a new Docker image. The default settings are:

  • dockerfile: ${projectDir}/Dockerfile.
  • imageName: project.name
  • tags: project.version and latest. For more information see Configuration section.

The dockerPush task

The dockerPush task will push the Docker image to a Docker repository. If authentication is required use docker login to add the credential to your $HOME/.docker/config.json file. This is how it looks like when the example project pushed to DockerHub.


The following configuration can be added to your Gradle build file:

docker {
    // Image version. Optional, default = project.version
    imageVersion = "version"
    // Image name. Optional, default = project.name
    imageName = "name"
    // Docker repository. Optional, default == no repository
    dockerRepository = 'sglahn'
    // Path to the Dockerfile to use. Optional, 
    // default = ${projectDir}/Dockerfile
    dockerFile = 'src/main/docker/Dockerfile'
    // Add a list of tags for an image. Optional, default = $applicationVersion
    tags = [version, 'latest', 'Hello']
    // Set metadata for an image. Optional, default = no label applied
    labels = ['branch=master', 'mylabel=test']
    // name and value of a buildarg. Optional, default = no build arguments
    buildArgs = ['http_proxy="http://some.proxy.url"']
    // Always remove intermediate containers, even after unsuccessful builds. 
    // Optional, default = false
    removeIntermediateContainers = true
    // Isolation specifies the type of isolation technology used by containers. 
    // Optional, default = default
    isolation = 'default'
    // Do not use cache when building the image. Optional, default = false
    noCache = true
    // Always attempt to pull a newer version of the image. 
    // Optional, default false
    pull = true
    // Suppress the build output and print image ID on success. 
    // Optional, default = true
    quiet = false