Class DockerService

java.lang.Object
io.github.pgatzka.docker.service.DockerService
All Implemented Interfaces:
AutoCloseable, org.gradle.api.services.BuildService<org.gradle.api.services.BuildServiceParameters.None>

public abstract class DockerService extends Object implements org.gradle.api.services.BuildService<org.gradle.api.services.BuildServiceParameters.None>, AutoCloseable
Gradle BuildService that owns a single DockerClient for the whole build. The first call to getClient() constructs the client lazily and pings the daemon (the precheck runs at most once per service instance). Implements AutoCloseable so Gradle closes the underlying HTTP client at build end.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    Close the underlying DockerClient, if any, and reset internal state so the service can be reused.
    com.github.dockerjava.api.DockerClient
    Lazily construct the shared DockerClient on first call and verify the daemon is reachable; subsequent calls return the cached client without re-pinging.

    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.services.BuildService

    getParameters
  • Constructor Details

    • DockerService

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

    • getClient

      public com.github.dockerjava.api.DockerClient getClient()
      Lazily construct the shared DockerClient on first call and verify the daemon is reachable; subsequent calls return the cached client without re-pinging.
      Returns:
      the shared DockerClient after a successful daemon precheck
      Throws:
      org.gradle.api.GradleException - if the daemon is unreachable on the first call
    • close

      public void close() throws IOException
      Close the underlying DockerClient, if any, and reset internal state so the service can be reused. Called by Gradle at the end of the build.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - if the underlying client's close fails