Class StartContainerTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
io.github.pgatzka.docker.task.DockerTask
io.github.pgatzka.docker.task.container.StartContainerTask
All Implemented Interfaces:
Comparable<org.gradle.api.Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, org.gradle.api.Named, org.gradle.api.plugins.ExtensionAware, org.gradle.api.Task, org.gradle.util.Configurable<org.gradle.api.Task>

@UntrackedTask(because="Docker daemon side effects must always run") public abstract class StartContainerTask extends DockerTask
Starts a Docker container according to its ContainerSpec. Pulls the image (subject to the configured PullPolicy), creates the container if it does not yet exist, starts it, and blocks until the configured Waitable readiness strategy is satisfied.

Idempotent against re-runs: an existing running container is left alone, and a stopped container with the same name is reused rather than recreated. Marked UntrackedTask because the daemon side effect must always run.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.gradle.api.Named

    org.gradle.api.Named.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

    Constructors
    Constructor
    Description
    Invoked by Gradle's bytecode-decorated subclass; not for direct use.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Gradle entry point for this task.
    abstract org.gradle.api.provider.ListProperty<BindMount>
    Mirrors ContainerSpec.bindMounts: host-path bind mounts to attach.
    abstract org.gradle.api.provider.ListProperty<String>
    Mirrors ContainerSpec.command: override for the image's CMD, or empty to keep the image default.
    abstract org.gradle.api.provider.Property<String>
    Mirrors ContainerSpec.name: the container name registered on the daemon.
    abstract org.gradle.api.provider.MapProperty<String,String>
    Container environment values, mirroring ContainerSpec.env.
    abstract org.gradle.api.provider.Property<String>
    Mirrors ContainerSpec.image: the image reference (e.g.
    abstract org.gradle.api.provider.ListProperty<String>
    Mirrors ContainerSpec.networks: declared networks; the first becomes the container's primary network and any remaining ones are attached after creation.
    abstract org.gradle.api.provider.MapProperty<Integer,Integer>
    Mirrors ContainerSpec.ports: host port to container port mappings.
    abstract org.gradle.api.provider.Property<PullPolicy>
    Mirrors ContainerSpec.pullPolicy: when (if ever) to pull the image before start.
    abstract org.gradle.api.provider.ListProperty<VolumeMount>
    Mirrors ContainerSpec.volumeMounts: named-volume mounts to attach.
    abstract org.gradle.api.provider.Property<Waitable>
    Mirrors ContainerSpec.waitFor: the readiness strategy applied after start.
    abstract org.gradle.api.provider.Property<Duration>
    Mirrors ContainerSpec.waitTimeout: maximum time to wait for readiness.

    Methods inherited from class io.github.pgatzka.docker.task.DockerTask

    getDockerService

    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, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService

    Methods inherited from class org.gradle.api.internal.AbstractTask

    acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, 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, notCompatibleWithConfigurationCache
  • Constructor Details

    • StartContainerTask

      public StartContainerTask()
      Invoked by Gradle's bytecode-decorated subclass; not for direct use.
  • Method Details

    • getContainerName

      @Input public abstract org.gradle.api.provider.Property<String> getContainerName()
      Mirrors ContainerSpec.name: the container name registered on the daemon.
      Returns:
      the container name property
    • getImage

      @Input public abstract org.gradle.api.provider.Property<String> getImage()
      Mirrors ContainerSpec.image: the image reference (e.g. postgres:16-alpine).
      Returns:
      the image reference property
    • getEnvironment

      @Internal public abstract org.gradle.api.provider.MapProperty<String,String> getEnvironment()
      Container environment values, mirroring ContainerSpec.env. Marked @Internal on purpose: env values commonly carry secrets and we do not want them fingerprinted into Gradle's task input snapshot or surfaced in build scans / cache snapshots.
      Returns:
      the environment map property
    • getPorts

      @Input public abstract org.gradle.api.provider.MapProperty<Integer,Integer> getPorts()
      Mirrors ContainerSpec.ports: host port to container port mappings.
      Returns:
      the port mappings property
    • getNetworks

      @Input public abstract org.gradle.api.provider.ListProperty<String> getNetworks()
      Mirrors ContainerSpec.networks: declared networks; the first becomes the container's primary network and any remaining ones are attached after creation.
      Returns:
      the networks property
    • getCommand

      @Input public abstract org.gradle.api.provider.ListProperty<String> getCommand()
      Mirrors ContainerSpec.command: override for the image's CMD, or empty to keep the image default.
      Returns:
      the command override property
    • getVolumeMounts

      @Input public abstract org.gradle.api.provider.ListProperty<VolumeMount> getVolumeMounts()
      Mirrors ContainerSpec.volumeMounts: named-volume mounts to attach.
      Returns:
      the volume mounts property
    • getBindMounts

      @Input public abstract org.gradle.api.provider.ListProperty<BindMount> getBindMounts()
      Mirrors ContainerSpec.bindMounts: host-path bind mounts to attach.
      Returns:
      the bind mounts property
    • getWaitFor

      @Input public abstract org.gradle.api.provider.Property<Waitable> getWaitFor()
      Mirrors ContainerSpec.waitFor: the readiness strategy applied after start.
      Returns:
      the readiness strategy property
    • getWaitTimeout

      @Input public abstract org.gradle.api.provider.Property<Duration> getWaitTimeout()
      Mirrors ContainerSpec.waitTimeout: maximum time to wait for readiness.
      Returns:
      the readiness timeout property
    • getPullPolicy

      @Input public abstract org.gradle.api.provider.Property<PullPolicy> getPullPolicy()
      Mirrors ContainerSpec.pullPolicy: when (if ever) to pull the image before start.
      Returns:
      the pull policy property
    • execute

      public void execute()
      Gradle entry point for this task. Delegates to the package-private run(DockerClient, StartContainerTaskParams, Logger) helper.