This plugin for Gradle adds the capability to build, run and push Docker images. Plugin uses Docker remote API that are handled by Docker Java library
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.sgornostal:gradle-docker-plugin:<version>'
}
}buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.org.sgornostal:gradle-docker-plugin:<version>"
}
}apply plugin: 'org.sgornostal.docker'or
apply plugin: 'docker'Configuration properties in the plugin extension docker and dockerRegistries are applied to all Docker tasks.
Example:
docker {
imageName = 'my-awesome-image'
buildArgs = ['ARG_NAME': 'ARG_VALUE']
tags 'latest', project.version
files jar.archivePath
dependsOn build
}Available properties are:
host- the server URL to connect to via Docker’s remote API. (string, optional, default: windows -tcp://localhost:2375, unix -unix:///var/run/docker.sock)tlsVerify- verify TLS (boolean, optional, default:false)certPath- the path to certificates for communicating with Docker over SSL (string, optional)imageName- docker image name (string, optional, default:${project.name})dockerFile- Relative path to dockerfile (string, optional, default:Dockerfile)buildArgs- an map of string to string which will set --build-arg arguments to the docker build command (map<string,string>, optional)tags- an arguments list or set of tags to create (set<string>, optional)files- an argument list of files to be included in the Docker build context (file..arg, optional)dependsOn- an argument list of tasks to be executed before build docker image (string, ref, optional)
Example:
docker {
run {
command 'ping', 'google.com'
volumes '/foo:/foo', '/bar:/bar'
ports '8080:8080', '443:4433'
env 'MYVAR1=foo', 'MYVAR2=bar'
}
...
}Available properties are:
command- an arguments list or list of container commands (string..args or list<string>, optional)volumes- an arguments list or list of mounted volumes (string..args or list<string>, optional)ports- an arguments list or list of publish or exposed ports (string..args or list<string>, optional)env- an arguments list or list of environment variables (string..args or list<string>, optional)attach- attach container output to task thread (boolean, optional, default:true)
Example:
docker {
clean {
force = true
}
...
}Available properties are:
force- force delete of image (boolean, optional, default:true)
Example:
dockerRegistries {
myRegistry {
url = 'localhost:18067'
email = '[email protected]'
username = 'user'
password = 'pwd'
}
hub {
email = '[email protected]'
username = 'user'
password = 'pwd'
}
...
}Available properties are:
url- registry url (string, optional, default:index.docker.io)email- registry email (string, optional)username- registry username (username, optional)password- registry password (password, optional)
dockerRegistries extension will create push task for each registry.
In the example above, tasks pushDockerToMyRegistry and pushDockerToHub will be created.
prepareDocker- prepare docker classpath. CopyingdockerFileandfilesif specified in configurationcleanDocker- remove docker imagebuildDocker- build docker imagerunDocker- create and run docker containerstopDocker- stop docker containerpushDockerTo%s- push docker to registry, where%sis capitalized name of a registry fromdockerRegistriesconfiguration