Class DockerBuildImage

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
com.bmuschko.gradle.docker.tasks.AbstractDockerRemoteApiTask
com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
All Implemented Interfaces:
RegistryCredentialsAware, Comparable<Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, ExtensionAware, Task, Configurable<Task>

public class DockerBuildImage extends AbstractDockerRemoteApiTask implements RegistryCredentialsAware
  • Constructor Details

    • DockerBuildImage

      public DockerBuildImage()
  • Method Details

    • getInputDir

      Input directory containing the build context. Defaults to "$buildDir/docker".
    • getDockerFile

      The Dockerfile to use to build the image. If null, will use 'Dockerfile' in the build context, i.e. "$inputDir/Dockerfile".
    • getImages

      @Input @Optional public final SetProperty<String> getImages()
      The images including repository, image name and tag to be built e.g. vieux/apache:2.0.
      Since:
      6.0.0
    • getNoCache

      @Input @Optional public final Property<Boolean> getNoCache()
      When true, do not use docker cache when building the image.
    • getRemove

      @Input @Optional public final Property<Boolean> getRemove()
      When true, remove intermediate containers after a successful build.
    • getQuiet

      @Input @Optional public final Property<Boolean> getQuiet()
      When true, suppress the build output and print image ID on success.
    • getPull

      @Input @Optional public final Property<Boolean> getPull()
      When true, always attempt to pull a newer version of the image.
    • getLabels

      @Input @Optional public MapProperty<String,String> getLabels()
      Labels to attach as metadata for to the image.

      This property is not final to allow build authors to remove the labels from the up-to-date check by extending DockerBuildImage and annotating the overrided getLabels() method with @Internal, example:

       import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
      
       class CustomDockerBuildImage extends DockerBuildImage {
          @Override
          @Internal
           MapProperty<String, String> getLabels() {
               super.getLabels()
           }
       }
       

      A use case for excluding the labels from the up-to-date check is if build author wants to set build information as labels (date, version-control-revision).

    • getNetwork

      @Input @Optional public final Property<String> getNetwork()
      Networking mode for the RUN instructions during build.
    • getBuildArgs

      @Input @Optional public final MapProperty<String,String> getBuildArgs()
      Build-time variables to pass to the image build.
    • getCacheFrom

      @Input @Optional public final SetProperty<String> getCacheFrom()
      Images to consider as cache sources.
    • getShmSize

      @Input @Optional public final Property<Long> getShmSize()
      Size of /dev/shm in bytes. The size must be greater than 0. If omitted the system uses 64MB.
    • getMemory

      @Input @Optional public final Property<Long> getMemory()
      Memory allocated for build specified in bytes (no suffix is needed)
      Since:
      7.3.0
    • getTarget

      @Input @Optional public final Property<String> getTarget()
      With this parameter it is possible to build a special stage in a multi-stage Docker file.

      This feature is only available for use with Docker 17.05 and higher.

      Since:
      4.10.0
    • getExtraHosts

      @Input @Optional public final SetProperty<String> getExtraHosts()
      Build-time additional host list to pass to the image build in the format host:ip.
      Since:
      6.2.0
    • getPlatform

      @Input @Optional public final Property<String> getPlatform()
      The target platform in the format os[/arch[/variant]], for example linux/s390x or darwin.
      Since:
      7.1.0
    • getRegistryCredentials

      public final DockerRegistryCredentials getRegistryCredentials()
      The target Docker registry credentials for usage with a task.
      Specified by:
      getRegistryCredentials in interface RegistryCredentialsAware
    • getImageIdFile

      @OutputFile public final RegularFileProperty getImageIdFile()
      Output file containing the image ID of the built image. Defaults to "$buildDir/.docker/$taskpath-imageId.txt". If path contains ':' it will be replaced by '_'.
      Since:
      4.9.0
    • getImageId

      @Internal public final Property<String> getImageId()
      The ID of the image built. The value of this property requires the task action to be executed.
    • runRemoteCommand

      public void runRemoteCommand() throws Exception
      Specified by:
      runRemoteCommand in class AbstractDockerRemoteApiTask
      Throws:
      Exception
    • registryCredentials

      public void registryCredentials(Action<? super DockerRegistryCredentials> action)
      Configures the target Docker registry credentials for use with a task.
      Specified by:
      registryCredentials in interface RegistryCredentialsAware
      Parameters:
      action - The action against the Docker registry credentials