Class ContainerSpec

java.lang.Object
io.github.pgatzka.docker.dsl.spec.ContainerSpec
All Implemented Interfaces:
org.gradle.api.Named

public abstract class ContainerSpec extends Object implements org.gradle.api.Named
Spec describing a single Docker container the plugin will manage. Created by Gradle's ObjectFactory once per name registered in docker { containers { register(...) }}.
  • Nested Class Summary

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

    org.gradle.api.Named.Namer
  • Constructor Summary

    Constructors
    Constructor
    Description
    Invoked by Gradle's ObjectFactory when a container is registered.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract org.gradle.api.provider.ListProperty<String>
    Override the image's default CMD.
    abstract org.gradle.api.provider.Property<String>
    Docker container name to use at docker run time.
    abstract org.gradle.api.provider.MapProperty<String,String>
    Environment variables passed to the container as -e KEY=VALUE pairs.
    abstract org.gradle.api.provider.Property<String>
    Image reference, e.g.
    Mutable builder collecting volume and bind mounts declared via mounts(Action).
     
    abstract org.gradle.api.provider.ListProperty<String>
    Names of networks (declared in docker.networks) this container should attach to.
    abstract org.gradle.api.provider.MapProperty<Integer,Integer>
    Published ports: keys are host ports, values are container ports.
    abstract org.gradle.api.provider.Property<PullPolicy>
    When the plugin should pull the image.
    abstract org.gradle.api.provider.Property<Duration>
    Grace period passed to docker stop before SIGKILL.
    abstract org.gradle.api.provider.Property<Waitable>
    Readiness strategy used by the generated start<ContainerName> task.
    abstract org.gradle.api.provider.Property<Duration>
    Maximum time the start task waits for getWait() to succeed before failing.
    void
    mounts(org.gradle.api.Action<? super Mounts> action)
    Configure volume and bind mounts for this container.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ContainerSpec

      @Inject public ContainerSpec(String name)
      Invoked by Gradle's ObjectFactory when a container is registered. Sets default conventions: containerName mirrors name, wait defaults to Waitable.none(), waitTimeout to 60s, stopTimeout to 10s, and pullPolicy to PullPolicy.IF_NOT_PRESENT.
      Parameters:
      name - logical container name as registered in the DSL
  • Method Details

    • getImage

      public abstract org.gradle.api.provider.Property<String> getImage()
      Image reference, e.g. postgres:16-alpine. Required.
      Returns:
      the image property
    • getContainerName

      public abstract org.gradle.api.provider.Property<String> getContainerName()
      Docker container name to use at docker run time. Defaults to the logical DSL name.
      Returns:
      the container-name property
    • getEnvironment

      public abstract org.gradle.api.provider.MapProperty<String,String> getEnvironment()
      Environment variables passed to the container as -e KEY=VALUE pairs.
      Returns:
      the environment property
    • getPorts

      public abstract org.gradle.api.provider.MapProperty<Integer,Integer> getPorts()
      Published ports: keys are host ports, values are container ports. Example: ports.set(mapOf(5432 to 5432)) maps host 5432 → container 5432.
      Returns:
      the ports property
    • getNetworks

      public abstract org.gradle.api.provider.ListProperty<String> getNetworks()
      Names of networks (declared in docker.networks) this container should attach to.
      Returns:
      the networks property
    • getCommand

      public abstract org.gradle.api.provider.ListProperty<String> getCommand()
      Override the image's default CMD. Each entry becomes one argv element.
      Returns:
      the command property
    • getWait

      public abstract org.gradle.api.provider.Property<Waitable> getWait()
      Readiness strategy used by the generated start<ContainerName> task. Defaults to Waitable.none().
      Returns:
      the wait property
    • getWaitTimeout

      public abstract org.gradle.api.provider.Property<Duration> getWaitTimeout()
      Maximum time the start task waits for getWait() to succeed before failing. Defaults to 60 seconds.
      Returns:
      the wait-timeout property
    • getStopTimeout

      public abstract org.gradle.api.provider.Property<Duration> getStopTimeout()
      Grace period passed to docker stop before SIGKILL. Defaults to 10 seconds.
      Returns:
      the stop-timeout property
    • getPullPolicy

      public abstract org.gradle.api.provider.Property<PullPolicy> getPullPolicy()
      When the plugin should pull the image. Defaults to PullPolicy.IF_NOT_PRESENT.
      Returns:
      the pull-policy property
    • mounts

      public void mounts(org.gradle.api.Action<? super Mounts> action)
      Configure volume and bind mounts for this container.
      Parameters:
      action - configuration block applied to the shared Mounts builder
    • getName

      public String getName()
      Specified by:
      getName in interface org.gradle.api.Named
    • getMounts

      public Mounts getMounts()
      Mutable builder collecting volume and bind mounts declared via mounts(Action).
      Returns:
      the mounts builder