Class Dockerfile

    • Constructor Detail

      • Dockerfile

        public Dockerfile()
    • Method Detail

      • getDestFile

        @OutputFile
        public final RegularFileProperty 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.

      • getDestDir

        @Internal
        public Provider<Directory> getDestDir()
        Returns a provider representing the destination directory containing the Dockerfile.
        Returns:
        The destination directory containing the Dockerfile
        Since:
        4.4.0
      • instruction

        public void instruction​(String 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(Provider)
      • instruction

        public void instruction​(Provider<String> provider)
        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:
        instruction(String)
      • from

        public void from​(String image)
        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(From), from(Provider)
      • from

        public void from​(Dockerfile.From 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(String), from(Provider)
      • from

        public void from​(Provider<Dockerfile.From> provider)
        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:
        from(From)
      • arg

        public void arg​(String 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(Provider)
      • arg

        public void arg​(Provider<String> provider)
        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:
        arg(String)
      • runCommand

        public 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.

        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(Provider)
      • runCommand

        public void runCommand​(Provider<String> provider)
        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:
        runCommand(String)
      • defaultCommand

        public void defaultCommand​(String... command)
        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(Provider)
      • defaultCommand

        public void defaultCommand​(Provider<List<String>> provider)
        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:
        defaultCommand(String...)
      • exposePort

        public void exposePort​(Integer... ports)
        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(Provider)
      • exposePort

        public void exposePort​(Provider<List<Integer>> provider)
        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:
        exposePort(Integer...)
      • environmentVariable

        public void environmentVariable​(String key,
                                        String value)
        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 - Key
        value - Value
        See Also:
        environmentVariable(Map), environmentVariable(Provider)
      • environmentVariable

        public void environmentVariable​(Provider<Map<String,​String>> provider)
        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:
        environmentVariable(String, String), environmentVariable(Map)
      • addFile

        public 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>.

        Example in Groovy DSL:

         task createDockerfile(type: Dockerfile) {
             addFile('test', '/absoluteDir/')
         }
         
        The produced instruction looks as follows:

         ADD test /absoluteDir/
         
        Parameters:
        src - The source path
        dest - The destination path
        See Also:
        addFile(File), addFile(Provider)
      • addFile

        public void 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>.

        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(String, String), addFile(Provider)
      • addFile

        public void addFile​(Provider<Dockerfile.File> provider)
        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:
        addFile(String, String), addFile(File)
      • copyFile

        public 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>.

        Example in Groovy DSL:

         task createDockerfile(type: Dockerfile) {
             copyFile('test', '/absoluteDir/')
         }
         
        The produced instruction looks as follows:

         COPY test /absoluteDir/
         
        Parameters:
        src - The source path
        dest - The destination path
        See Also:
        copyFile(CopyFile), copyFile(Provider)
      • copyFile

        public 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>.

        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(String, String), copyFile(Provider)
      • copyFile

        public void copyFile​(Provider<Dockerfile.CopyFile> provider)
        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:
        copyFile(String, String), copyFile(CopyFile)
      • entryPoint

        public void entryPoint​(String... 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(Provider)
      • entryPoint

        public void entryPoint​(Provider<List<String>> provider)
        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:
        entryPoint(String...)
      • volume

        public 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.

        Example in Groovy DSL:

         task createDockerfile(type: Dockerfile) {
             volume('/myvol')
         }
         
        The produced instruction looks as follows:

         VOLUME ["/myvol"]
         
        Parameters:
        volume - Volume
        See Also:
        volume(Provider)
      • volume

        public void volume​(Provider<List<String>> provider)
        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:
        volume(String...)
      • user

        public 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.

        Example in Groovy DSL:

         task createDockerfile(type: Dockerfile) {
             user('patrick')
         }
         
        The produced instruction looks as follows:

         USER patrick
         
        Parameters:
        user - User
        See Also:
        user(Provider)
      • user

        public void user​(Provider<String> provider)
        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:
        user(String)
      • workingDir

        public void workingDir​(String dir)
        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(Provider)
      • workingDir

        public void workingDir​(Provider<String> provider)
        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:
        workingDir(String)
      • onBuild

        public 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.

        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(Provider)
      • onBuild

        public void onBuild​(Provider<String> provider)
        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:
        onBuild(String)
      • label

        public void label​(Map<String,​String> labels)
        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(Provider)
      • label

        public void label​(Provider<Map<String,​String>> provider)
        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:
        label(Map)