Class Dockerfile
- All Implemented Interfaces:
Comparable<Task>
,org.gradle.api.internal.DynamicObjectAware
,org.gradle.api.internal.TaskInternal
,ExtensionAware
,Task
,Configurable<Task>
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Represents aADD
instruction.static class
Represents aARG
instruction.static class
Represents a comment instruction.static class
Input data for aDockerfile.CopyFileInstruction
.static class
Represents aCOPY
instruction.static class
Represents aCMD
instruction.static class
Represents aENTRYPOINT
instruction.static class
Represents aENV
instruction.static class
Represents aEXPOSE
instruction.static class
Input data for aDockerfile.AddFileInstruction
orDockerfile.CopyFileInstruction
.static class
Dockerfile.FileInstruction<T extends Dockerfile.File>
An instruction whose value is a Dockerfile.File.static class
Input data for aDockerfile.FromInstruction
.static class
Represents aFROM
instruction.static class
An instruction that uses the provided value as-is without any additional formatting.static class
Input data for aDockerfile.HealthcheckInstruction
.static class
static interface
A representation of an instruction in a Dockerfile.static class
Represents aLABEL
instruction.static class
An instruction whose value is a Map.static class
Represents aONBUILD
instruction.static class
Represents aRUN
instruction.static class
An instruction whose value is a String array.static class
An instruction whose value is a String.static class
Represents aUSER
instruction.static class
static class
Represents aWORKDIR
instruction.Nested classes/interfaces inherited from interface org.gradle.api.Task
Task.Namer
-
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFile
(Dockerfile.File file) The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the container at the path <dest>.void
The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the container at the path <dest>.void
addFile
(Provider<Dockerfile.File> provider) An ADD instruction as Provider.void
The ARG instruction defines a variable that users can pass at build-time to the builder.void
An ARG instruction as Provider.void
copyFile
(Dockerfile.CopyFile file) The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.void
The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.void
copyFile
(Provider<Dockerfile.CopyFile> provider) A COPY instruction as Provider.void
create()
void
defaultCommand
(String... command) The main purpose of a CMD instruction is to provide defaults for an executing container.void
defaultCommand
(Provider<List<String>> provider) A CMD instruction as Provider.void
entryPoint
(String... entryPoint) An ENTRYPOINT allows you to configure a container that will run as an executable.void
entryPoint
(Provider<List<String>> provider) A ENTRYPOINT as Provider.void
environmentVariable
(String key, String value) The ENV instruction sets the environment variable <key> to the value <value>.void
environmentVariable
(Map<String, String> envVars) A ENV instruction as Map.void
environmentVariable
(Provider<Map<String, String>> provider) A ENV instruction as Provider.void
exposePort
(Integer... ports) The EXPOSE instruction informs Docker that the container will listen on the specified network ports at runtime.void
exposePort
(Provider<List<Integer>> provider) A EXPOSE instruction as Provider.void
from
(Dockerfile.From from) The FROM instruction sets the Base Image for subsequent instructions.void
The FROM instruction sets the Base Image for subsequent instructions.void
from
(Provider<Dockerfile.From> provider) A FROM instruction as Provider.Returns a provider representing the destination directory containing the Dockerfile.final RegularFileProperty
The destination file representing the Dockerfile.Returns all instructions used to generate the Dockerfile.void
healthcheck
(Dockerfile.Healthcheck healthcheck) The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working.void
healthcheck
(Provider<Dockerfile.Healthcheck> provider) The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working.void
instruction
(String instruction) Adds a full instruction as String.void
instruction
(Provider<String> provider) Adds a full instruction as Provider.void
instructionsFromTemplate
(File template) Adds instructions to the Dockerfile from a template file.void
instructionsFromTemplate
(String templatePath) Adds instructions to the Dockerfile from a template file.void
instructionsFromTemplate
(Provider<RegularFile> provider) Adds instructions to the Dockerfile from a template file.void
The LABEL instruction adds metadata to an image.void
A LABEL instruction as Provider.void
The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build.void
A ONBUILD instruction as Provider.void
runCommand
(String command) The RUN instruction will execute any commands in a new layer on top of the current image and commit the results.void
runCommand
(Provider<String> provider) A RUN instruction as Provider.void
The USER instruction sets the user name or UID to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.void
A USER instruction as Provider.void
The VOLUME instruction will create a mount point with the specified name and mark it as holding externally mounted volumes from native host or other containers.void
A VOLUME instruction as Provider.void
workingDir
(String dir) The WORKDIR instruction sets the working directory for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.void
workingDir
(Provider<String> provider) A WORKDIR instruction as Provider.Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService
Methods inherited from class org.gradle.api.internal.AbstractTask
appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjects
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
Constructor Details
-
Dockerfile
public Dockerfile()
-
-
Method Details
-
getDestFile
The destination file representing the Dockerfile. The destination file encourages the conventional file name Dockerfile but allows any arbitrary file name.Defaults to
$buildDir/docker/Dockerfile
.The method
getDestDir()
returns the parent directory of the Dockerfile. -
getInstructions
Returns all instructions used to generate the Dockerfile.- Returns:
- All instructions
-
getDestDir
Returns a provider representing the destination directory containing the Dockerfile.- Returns:
- The destination directory containing the Dockerfile
- Since:
- 4.4.0
-
create
- Throws:
IOException
-
instructionsFromTemplate
Adds instructions to the Dockerfile from a template file. The template file can have any name.- Parameters:
template
- The template file- Throws:
IOException
- See Also:
-
instructionsFromTemplate
Adds instructions to the Dockerfile from a template file. The path can be relative to the project root directory or absolute.- Parameters:
templatePath
- The path to the template file- Throws:
IOException
- See Also:
-
instructionsFromTemplate
Adds instructions to the Dockerfile from a template file. Currently, the provider is evaluated as soon as the method is called which means that the provider is not evaluated lazily. This behavior might change in the future.- Parameters:
provider
- The provider of the template file- Throws:
IOException
- Since:
- 4.0.0
- See Also:
-
instruction
Adds a full instruction as String.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { instruction('FROM ubuntu:14.04') instruction('LABEL maintainer=benjamin.muschko@gmail.com') }
The produced instructions look as follows:FROM ubuntu:14.04 LABEL maintainer=benjamin.muschko@gmail.com
- Parameters:
instruction
- Instruction as String- See Also:
-
instruction
Adds a full instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { instruction(project.provider(new Callable<String>() { @Override String call() throws Exception { 'FROM ubuntu:14.04' } })) }
The produced instruction looks as follows:FROM ubuntu:14.04
- Parameters:
provider
- Instruction as Provider- Since:
- 4.0.0
- See Also:
-
from
The FROM instruction sets the Base Image for subsequent instructions.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { from('ubuntu:14.04') }
The produced instruction looks as follows:FROM ubuntu:14.04
- Parameters:
image
- From definition- See Also:
-
from
The FROM instruction sets the Base Image for subsequent instructions.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { from(new From('ubuntu:14.04')) }
The produced instruction looks as follows:FROM ubuntu:14.04
- Parameters:
from
- From definition- See Also:
-
from
A FROM instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { from(project.provider(new Callable<Dockerfile.From>() { @Override Dockerfile.From call() throws Exception { new Dockerfile.From('ubuntu:14.04') } })) }
The produced instruction looks as follows:FROM ubuntu:14.04
- Parameters:
provider
- From information as Provider- Since:
- 4.0.0
- See Also:
-
arg
The ARG instruction defines a variable that users can pass at build-time to the builder.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { arg('user1=someuser') }
The produced instruction looks as follows:ARG user1=someuser
- Parameters:
arg
- Argument to pass, possibly with default value.- See Also:
-
arg
An ARG instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { arg(project.provider(new Callable<String>() { @Override String call() throws Exception { 'user1=someuser' } })) }
The produced instruction looks as follows:ARG user1=someuser
- Parameters:
provider
- Argument to pass as Provider- Since:
- 4.0.0
- See Also:
-
runCommand
The RUN instruction will execute any commands in a new layer on top of the current image and commit the results.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { runCommand('/bin/bash -c echo hello') }
The produced instruction looks as follows:RUN /bin/bash -c echo hello
- Parameters:
command
- Command- See Also:
-
runCommand
A RUN instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { runCommand(project.provider(new Callable<String>() { @Override String call() throws Exception { '/bin/bash -c echo hello' } })) }
The produced instruction looks as follows:RUN /bin/bash -c echo hello
- Parameters:
provider
- Command as Provider- Since:
- 4.0.0
- See Also:
-
defaultCommand
The main purpose of a CMD instruction is to provide defaults for an executing container.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { defaultCommand('/usr/bin/wc', '--help') }
The produced instruction looks as follows:CMD ["/usr/bin/wc", "--help"]
- Parameters:
command
- Command- See Also:
-
defaultCommand
A CMD instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { defaultCommand(project.provider(new Callable<List<String>>() { @Override List<String> call() throws Exception { ['/usr/bin/wc', '--help'] } })) }
The produced instruction looks as follows:CMD ["/usr/bin/wc", "--help"]
- Parameters:
provider
- Command as Provider- Since:
- 4.0.0
- See Also:
-
exposePort
The EXPOSE instruction informs Docker that the container will listen on the specified network ports at runtime.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { exposePort(8080, 9090) }
The produced instruction looks as follows:EXPOSE 8080 9090
- Parameters:
ports
- Ports- See Also:
-
exposePort
A EXPOSE instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { exposePort(project.provider(new Callable<List<Integer>>() { @Override List<Integer> call() throws Exception { [8080, 9090] } })) }
The produced instruction looks as follows:EXPOSE 8080 9090
- Parameters:
provider
- Ports as Provider- Since:
- 4.0.0
- See Also:
-
environmentVariable
The ENV instruction sets the environment variable <key> to the value <value>. This value will be passed to all future RUN instructions.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { environmentVariable('MY_NAME', 'John Doe') }
The produced instruction looks as follows:ENV MY_NAME=John Doe
- Parameters:
key
- Keyvalue
- Value- See Also:
-
environmentVariable
A ENV instruction as Map.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { environmentVariable(['MY_NAME': 'John Doe']) }
The produced instruction looks as follows:ENV MY_NAME=John Doe
- Parameters:
envVars
- Environment variables- See Also:
-
environmentVariable
A ENV instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { environmentVariable(project.provider(new Callable<Map<String, String>>() { @Override Map<String, String> call() throws Exception { ['MY_NAME': 'John Doe'] } })) }
The produced instruction looks as follows:ENV MY_NAME=John Doe
- Parameters:
provider
- Environment variables as Provider- Since:
- 4.0.0
- See Also:
-
addFile
The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the container at the path <dest>.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { addFile('test', '/absoluteDir/') }
The produced instruction looks as follows:ADD test /absoluteDir/
- Parameters:
src
- The source pathdest
- The destination path- See Also:
-
addFile
The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the container at the path <dest>.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { addFile(new Dockerfile.File('test', '/absoluteDir/')) }
The produced instruction looks as follows:ADD test /absoluteDir/
- Parameters:
file
- Dockerfile.File definition- See Also:
-
addFile
An ADD instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { addFile(project.provider(new Callable<Dockerfile.File>() { @Override Dockerfile.File call() throws Exception { new Dockerfile.File('test', '/absoluteDir/') } })) }
The produced instruction looks as follows:ADD test /absoluteDir/
- Parameters:
provider
- Add instruction as Provider- Since:
- 4.0.0
- See Also:
-
copyFile
The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { copyFile('test', '/absoluteDir/') }
The produced instruction looks as follows:COPY test /absoluteDir/
- Parameters:
src
- The source pathdest
- The destination path- See Also:
-
copyFile
The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { copyFile(new Dockerfile.CopyFile('test', '/absoluteDir/')) }
The produced instruction looks as follows:COPY test /absoluteDir/
- Parameters:
file
- CopyFile definition- See Also:
-
copyFile
A COPY instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { copyFile(project.provider(new Callable<Dockerfile.CopyFile>() { @Override Dockerfile.CopyFile call() throws Exception { new Dockerfile.CopyFile('test', '/absoluteDir/') } })) }
The produced instruction looks as follows:COPY test /absoluteDir/
- Parameters:
provider
- Copy instruction as Provider- Since:
- 4.0.0
- See Also:
-
entryPoint
An ENTRYPOINT allows you to configure a container that will run as an executable.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { entryPoint('top', '-b') }
The produced instruction looks as follows:ENTRYPOINT ["top", "-b"]
- Parameters:
entryPoint
- Entry point- See Also:
-
entryPoint
A ENTRYPOINT as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { entryPoint(project.provider(new Callable<List<String>>() { @Override List<String> call() throws Exception { ['top', '-b'] } })) }
The produced instruction looks as follows:ENTRYPOINT ["top", "-b"]
- Parameters:
provider
- Entry point- Since:
- 4.0.0
- See Also:
-
volume
The VOLUME instruction will create a mount point with the specified name and mark it as holding externally mounted volumes from native host or other containers.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { volume('/myvol') }
The produced instruction looks as follows:VOLUME ["/myvol"]
- Parameters:
volume
- Volume- See Also:
-
volume
A VOLUME instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { volume(project.provider(new Callable<List<String>>() { @Override List<String> call() throws Exception { ['/myvol'] } })) }
The produced instruction looks as follows:VOLUME ["/myvol"]
- Parameters:
provider
- Volume- Since:
- 4.0.0
- See Also:
-
user
The USER instruction sets the user name or UID to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { user('patrick') }
The produced instruction looks as follows:USER patrick
- Parameters:
user
- User- See Also:
-
user
A USER instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { user(project.provider(new Callable<String>() { @Override String call() throws Exception { 'patrick' } })) }
The produced instruction looks as follows:USER patrick
- Parameters:
provider
- User as Provider- Since:
- 4.0.0
- See Also:
-
workingDir
The WORKDIR instruction sets the working directory for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { workingDir('/path/to/workdir') }
The produced instruction looks as follows:WORKDIR /path/to/workdir
- Parameters:
dir
- Directory- See Also:
-
workingDir
A WORKDIR instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { workingDir(project.provider(new Callable<String>() { @Override String call() throws Exception { '/path/to/workdir' } })) }
The produced instruction looks as follows:WORKDIR /path/to/workdir
- Parameters:
provider
- Directory- Since:
- 4.0.0
- See Also:
-
onBuild
The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { onBuild('ADD . /app/src') }
The produced instruction looks as follows:ONBUILD ADD . /app/src
- Parameters:
instruction
- Instruction- See Also:
-
onBuild
A ONBUILD instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { onBuild(project.provider(new Callable<String>() { @Override String call() throws Exception { 'ADD . /app/src' } })) }
The produced instruction looks as follows:ONBUILD ADD . /app/src
- Parameters:
provider
- Instruction- Since:
- 4.0.0
- See Also:
-
label
The LABEL instruction adds metadata to an image.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { label(['version': '1.0']) }
The produced instruction looks as follows:LABEL version=1.0
- Parameters:
labels
- Labels- See Also:
-
label
A LABEL instruction as Provider.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { label(project.provider(new Callable<Map<String, String>>() { @Override Map<String, String> call() throws Exception { ['version': '1.0'] } })) }
The produced instruction looks as follows:LABEL version=1.0
- Parameters:
provider
- Labels as Provider- Since:
- 4.0.0
- See Also:
-
healthcheck
The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { healthcheck(new Healthcheck("curl -f http://localhost/ || exit 1").withRetries(5)) }
The produced instruction looks as follows:HEALTHCHECK --retries=5 CMD curl -f http://localhost/ || exit 1
- Parameters:
healthcheck
- the healthcheck configuration- See Also:
-
healthcheck
The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working.Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { from(project.provider(new Callable<Dockerfile.Healthcheck>() { @Override Dockerfile.Healthcheck call() throws Exception { new Dockerfile.Healthcheck("curl -f http://localhost/ || exit 1") } })) }
The produced instruction looks as follows:HEALTHCHECK CMD curl -f http://localhost/ || exit 1
- Parameters:
provider
- Healthcheck information as Provider- See Also:
-