Creates a Dockerfile based on the provided instructions.
Modifiers | Name | Description |
---|---|---|
static class |
Dockerfile.AddFileInstruction |
Represents a ADD instruction. |
static class |
Dockerfile.ArgInstruction |
Represents a ARG instruction. |
static class |
Dockerfile.CommentInstruction |
Represents a comment instruction. |
static class |
Dockerfile.CopyFile |
Input data for a CopyFileInstruction. |
static class |
Dockerfile.CopyFileInstruction |
Represents a COPY instruction. |
static class |
Dockerfile.DefaultCommandInstruction |
Represents a CMD instruction. |
static class |
Dockerfile.EntryPointInstruction |
Represents a ENTRYPOINT instruction. |
static class |
Dockerfile.EnvironmentVariableInstruction |
Represents a ENV instruction. |
static class |
Dockerfile.ExposePortInstruction |
Represents a EXPOSE instruction. |
static class |
Dockerfile.File |
Input data for a AddFileInstruction or CopyFileInstruction. |
static class |
Dockerfile.FileInstruction |
An instruction whose value is a File. |
static class |
Dockerfile.From |
Input data for a FromInstruction. |
static class |
Dockerfile.FromInstruction |
Represents a FROM instruction. |
static class |
Dockerfile.GenericInstruction |
An instruction that uses the provided value as-is without any additional formatting. |
static interface |
Dockerfile.Instruction |
A representation of an instruction in a Dockerfile. |
static class |
Dockerfile.LabelInstruction |
Represents a LABEL instruction. |
static class |
Dockerfile.MapInstruction |
An instruction whose value is a Map. |
static class |
Dockerfile.OnBuildInstruction |
Represents a ONBUILD instruction. |
static class |
Dockerfile.RunCommandInstruction |
Represents a RUN instruction. |
static class |
Dockerfile.StringArrayInstruction |
An instruction whose value is a String array. |
static class |
Dockerfile.StringCommandInstruction |
An instruction whose value is a String. |
static class |
Dockerfile.UserInstruction |
Represents a USER instruction. |
static class |
Dockerfile.VolumeInstruction |
|
static class |
Dockerfile.WorkDirInstruction |
Represents a WORKDIR instruction. |
Fields inherited from class | Fields |
---|---|
class DefaultTask |
TASK_NAME, TASK_DESCRIPTION, TASK_GROUP, TASK_TYPE, TASK_DEPENDS_ON, TASK_OVERWRITE, TASK_ACTION, TASK_CONSTRUCTOR_ARGS |
class AbstractTask |
TASK_NAME, TASK_DESCRIPTION, TASK_GROUP, TASK_TYPE, TASK_DEPENDS_ON, TASK_OVERWRITE, TASK_ACTION, TASK_CONSTRUCTOR_ARGS |
Type | Name and description |
---|---|
RegularFileProperty |
destFile The destination file representing the Dockerfile. |
Constructor and description |
---|
Dockerfile
() |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
addFile(String src, String dest) 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(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 |
addFile(Provider<Dockerfile.File> provider) A ADD instruction as Provider. |
|
void |
arg(String arg) The ARG instruction defines a variable that users can pass at build-time to the builder. |
|
void |
arg(Provider<String> provider) A ARG instruction as Provider. |
|
void |
copyFile(String src, String dest) 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(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 |
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(String image) The FROM instruction sets the Base Image for subsequent instructions. |
|
void |
from(Dockerfile.From from) The FROM instruction sets the Base Image for subsequent instructions. |
|
void |
from(Provider<Dockerfile.From> provider) A FROM instruction as Provider. |
|
Provider<Directory> |
getDestDir() Returns a provider representing the destination directory containing the Dockerfile. |
|
ListProperty<Instruction> |
getInstructions() Returns all instructions used to generate the Dockerfile. |
|
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 |
label(Map<String, String> labels) The LABEL instruction adds metadata to an image. |
|
void |
label(Provider<Map<String, String>> provider) A LABEL instruction as Provider. |
|
void |
onBuild(String instruction) 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 |
onBuild(Provider<String> provider) 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 |
user(String 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. |
|
void |
user(Provider<String> provider) A USER instruction as Provider. |
|
void |
volume(String... 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. |
|
void |
volume(Provider<List<String>> provider) 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. |
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.
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/') }
src
- The source pathdest
- The destination pathThe 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/')) }
file
- File definitionA ADD instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { addFile(project.provider(new Callable() { @Override Dockerfile.File call() throws Exception { new Dockerfile.File('test', '/absoluteDir/') } })) }
provider
- Add instruction as ProviderThe 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') }
arg
- Argument to pass, possibly with default value.A ARG instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { arg(project.provider(new Callable() { @Override String call() throws Exception { 'user1=someuser' } })) }
provider
- Argument to pass as ProviderThe 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/') }
src
- The source pathdest
- The destination pathThe 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/')) }
file
- File definitionA COPY instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { copyFile(project.provider(new Callable() { @Override Dockerfile.CopyFile call() throws Exception { new Dockerfile.CopyFile('test', '/absoluteDir/') } })) }
provider
- Copy instruction as ProviderThe 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') }
command
- CommandA CMD instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { defaultCommand(project.provider(new Callable>() { @Override List
call() throws Exception { ['/usr/bin/wc', '--help'] } })) }
provider
- Command as ProviderAn ENTRYPOINT allows you to configure a container that will run as an executable.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { entryPoint('top', '-b') }
entryPoint
- Entry pointA ENTRYPOINT as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { entryPoint(project.provider(new Callable>() { @Override List
call() throws Exception { ['top', '-b'] } })) }
entryPoint
- Entry pointThe 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('myName', 'John Doe') }
key
- Keyvalue
- ValueA ENV instruction as Map.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { environmentVariable(['myName': 'John Doe']) }
envVars
- Environment variablesA ENV instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { environmentVariable(project.provider(new Callable
provider
- Environment variables as ProviderThe 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) }
ports
- PortsA EXPOSE instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { exposePort(project.provider(new Callable>() { @Override List
call() throws Exception { [8080, 9090] } })) }
ports
- Ports as ProviderThe FROM instruction sets the Base Image for subsequent instructions.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { from('ubuntu:14.04') }
from
- From definitionThe FROM instruction sets the Base Image for subsequent instructions.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { from(new From('ubuntu:14.04')) }
from
- From definitionstageName
- stage name in case of multi-stage builds (default null)A FROM instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { from(project.provider(new Callable() { @Override Dockerfile.From call() throws Exception { new Dockerfile.From('ubuntu:14.04') } })) }
provider
- From information as ProviderReturns a provider representing the destination directory containing the Dockerfile.
Returns all instructions used to generate the Dockerfile.
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') }
instruction
- Instruction as StringAdds a full instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { instruction(project.provider(new Callable() { @Override String call() throws Exception { 'FROM ubuntu:14.04' } })) }
provider
- Instruction as ProviderAdds instructions to the Dockerfile from a template file. The template file can have any name.
template
- The template fileAdds instructions to the Dockerfile from a template file. The path can be relative to the project root directory or absolute.
templatePath
- The path to the template fileAdds 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.
provider
- The provider of the template fileThe LABEL instruction adds metadata to an image.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { label(['version': '1.0']) }
labels
- LabelsA LABEL instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { label(project.provider(new Callable
provider
- Labels as ProviderThe 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') }
instruction
- InstructionA ONBUILD instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { onBuild(project.provider(new Callable() { @Override String call() throws Exception { 'ADD . /app/src' } })) }
instruction
- InstructionThe 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') }
command
- CommandA RUN instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { runCommand(project.provider(new Callable() { @Override String call() throws Exception { '/bin/bash -c echo hello' } })) }
provider
- Command as ProviderThe 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') }
user
- UserA USER instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { user(project.provider(new Callable() { @Override String call() throws Exception { 'patrick' } })) }
provider
- User as ProviderThe 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') }
volume
- VolumeA VOLUME instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { volume(project.provider(new Callable>() { @Override List
call() throws Exception { ['/myvol'] } })) }
volume
- VolumeThe 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') }
dir
- DirectoryA WORKDIR instruction as Provider.
Example in Groovy DSL:
task createDockerfile(type: Dockerfile) { workingDir(project.provider(new Callable() { @Override String call() throws Exception { '/path/to/workdir' } })) }
dir
- DirectoryGroovy Documentation