Skip to content

coacoas/gradle-docker-plugin

 
 

Repository files navigation

Gradle Docker plugin

Docker Logo

Gradle plugin for managing Docker images and containers using via its remote API. The heavy lifting of communicating with the Docker remote API is handled by the Docker Java library. Currently, version 0.8.2 is used which assumes Docker’s client API v1.12.

Usage

To use the plugin, include in your build script:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-docker-plugin:0.2'
    }
}

apply plugin: 'docker'

Custom task types

Misc

The plugin provides the following general-purpose custom task types:

Type Description

DockerInfo

Displays system-wide information.

DockerVersion

Show the docker version information.

Images

The plugin provides the following custom task types for managing images:

Type Description

DockerBuildImage

Builds an image from a Dockerfile.

DockerCommitImage

Creates a new image from a container’s changes.

DockerPullImage

Pulls an image from the registry.

DockerPushImage

Pushes an image to a registry.

DockerRemoveImage

Removes an image from the filesystem.

Containers

The plugin provides the following custom task types for managing containers:

Type Description

DockerCreateContainer

Creates a container.

DockerKillContainer

Kills the container for a given id.

DockerRemoveContainer

Removes the container for a given id from the filesystem.

DockerRestartContainer

Restarts the container for a given id.

DockerStartContainer

Starts the container for a given id.

DockerStopContainer

Stops the container for a given id.

DockerWaitContainer

Blocks until container for a given id stops, then returns the exit code.

Extension properties

The plugin defines the following extension properties in the docker closure:

Property name Type Default value Description

serverUrl

String

null

The server URL to connect to via Docker’s remote API.

Example

The following example code demonstrates how to build a Docker image from a Dockerfile, starts up a container for this image and exercises functional tests agains the running container. At the end of this operation, the container is stopped.

import org.gradle.api.plugins.docker.tasks.container.*
import org.gradle.api.plugins.docker.tasks.image.*

docker {
    serverUrl = 'http://remote.docker.com:4243'
}

ext.imageTag = 'test/myapp'

task buildMyAppImage(type: DockerBuildImage) {
    inputDir = file('docker/myapp')
    tag = imageTag
}

task createMyAppContainer(type: DockerCreateContainer) {
    dependsOn buildMyAppImage
    imageId = imageTag
}

task startMyAppContainer(type: DockerStartContainer) {
    dependsOn createMyAppContainer
    targetContainerId { createMyAppContainer.getContainerId() }
}

task stopMyAppContainer(type: DockerStopContainer) {
    targetContainerId { createMyAppContainer.getContainerId() }
}

task functionalTestMyApp(type: Test) {
    dependsOn startMyAppContainer
    finalizedBy stopMyAppContainer
}

About

Gradle plugin for managing Docker images and containers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published