Class CliDockerClient

  • All Implemented Interfaces:
    DockerClient

    public class CliDockerClient
    extends java.lang.Object
    implements DockerClient
    Calls out to the docker CLI.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CliDockerClient.DockerImageDetails
      Contains the size, image ID, and diff IDs of an image inspected with docker inspect.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.nio.file.Path DEFAULT_DOCKER_CLIENT
      Default path to the docker executable.
    • Constructor Summary

      Constructors 
      Constructor Description
      CliDockerClient​(java.nio.file.Path dockerExecutable, java.util.Map<java.lang.String,​java.lang.String> dockerEnvironment)
      Instantiates with a docker executable and environment variables.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CliDockerClient.DockerImageDetails inspect​(ImageReference imageReference)
      Gets the size, image ID, and diff IDs of an image in the Docker daemon.
      static boolean isDefaultDockerInstalled()
      Checks if Docker is installed on the user's system by running the `docker` command.
      static boolean isDockerInstalled​(java.nio.file.Path dockerExecutable)
      Checks if Docker is installed on the user's system and by verifying if the executable path provided has the appropriate permissions.
      java.lang.String load​(ImageTarball imageTarball, java.util.function.Consumer<java.lang.Long> writtenByteCountListener)
      Loads an image tarball into the Docker daemon.
      void save​(ImageReference imageReference, java.nio.file.Path outputPath, java.util.function.Consumer<java.lang.Long> writtenByteCountListener)
      Saves an image tarball from the Docker daemon.
      boolean supported​(java.util.Map<java.lang.String,​java.lang.String> parameters)
      Validate if the DockerClient is supported.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_DOCKER_CLIENT

        public static final java.nio.file.Path DEFAULT_DOCKER_CLIENT
        Default path to the docker executable.
    • Constructor Detail

      • CliDockerClient

        public CliDockerClient​(java.nio.file.Path dockerExecutable,
                               java.util.Map<java.lang.String,​java.lang.String> dockerEnvironment)
        Instantiates with a docker executable and environment variables.
        Parameters:
        dockerExecutable - path to docker
        dockerEnvironment - environment variables for docker
    • Method Detail

      • isDefaultDockerInstalled

        public static boolean isDefaultDockerInstalled()
        Checks if Docker is installed on the user's system by running the `docker` command.
        Returns:
        true if Docker is installed on the user's system and accessible
      • isDockerInstalled

        public static boolean isDockerInstalled​(java.nio.file.Path dockerExecutable)
        Checks if Docker is installed on the user's system and by verifying if the executable path provided has the appropriate permissions.
        Parameters:
        dockerExecutable - path to the executable to test running
        Returns:
        true if Docker is installed on the user's system and accessible
      • supported

        public boolean supported​(java.util.Map<java.lang.String,​java.lang.String> parameters)
        Description copied from interface: DockerClient
        Validate if the DockerClient is supported.
        Specified by:
        supported in interface DockerClient
        Parameters:
        parameters - to be used by the docker client
        Returns:
        true if conditions are met
      • load

        public java.lang.String load​(ImageTarball imageTarball,
                                     java.util.function.Consumer<java.lang.Long> writtenByteCountListener)
                              throws java.lang.InterruptedException,
                                     java.io.IOException
        Description copied from interface: DockerClient
        Loads an image tarball into the Docker daemon.
        Specified by:
        load in interface DockerClient
        Parameters:
        imageTarball - the built container tarball
        writtenByteCountListener - callback to call when bytes are loaded
        Returns:
        stdout from docker
        Throws:
        java.lang.InterruptedException - if the 'docker load' process is interrupted
        java.io.IOException - if streaming the blob to 'docker load' fails
        See Also:
        https://docs.docker.com/engine/reference/commandline/load
      • save

        public void save​(ImageReference imageReference,
                         java.nio.file.Path outputPath,
                         java.util.function.Consumer<java.lang.Long> writtenByteCountListener)
                  throws java.lang.InterruptedException,
                         java.io.IOException
        Description copied from interface: DockerClient
        Saves an image tarball from the Docker daemon.
        Specified by:
        save in interface DockerClient
        Parameters:
        imageReference - the image to save
        outputPath - the destination path to save the output tarball
        writtenByteCountListener - callback to call when bytes are saved
        Throws:
        java.lang.InterruptedException - if the 'docker save' process is interrupted
        java.io.IOException - if creating the tarball fails
        See Also:
        https://docs.docker.com/engine/reference/commandline/save
      • inspect

        public CliDockerClient.DockerImageDetails inspect​(ImageReference imageReference)
                                                   throws java.io.IOException,
                                                          java.lang.InterruptedException
        Description copied from interface: DockerClient
        Gets the size, image ID, and diff IDs of an image in the Docker daemon.
        Specified by:
        inspect in interface DockerClient
        Parameters:
        imageReference - the image to inspect
        Returns:
        the size, image ID, and diff IDs of the image
        Throws:
        java.io.IOException - if an I/O exception occurs or docker inspect failed
        java.lang.InterruptedException - if the docker inspect process was interrupted