Class CliDockerClient
- java.lang.Object
-
- com.google.cloud.tools.jib.docker.CliDockerClient
-
- All Implemented Interfaces:
DockerClient
public class CliDockerClient extends java.lang.Object implements DockerClient
Calls out to thedocker
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 withdocker 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 adocker
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.
-
-
-
Constructor Detail
-
CliDockerClient
public CliDockerClient(java.nio.file.Path dockerExecutable, java.util.Map<java.lang.String,java.lang.String> dockerEnvironment)
Instantiates with adocker
executable and environment variables.- Parameters:
dockerExecutable
- path todocker
dockerEnvironment
- environment variables fordocker
-
-
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 interfaceDockerClient
- 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 interfaceDockerClient
- Parameters:
imageTarball
- the built container tarballwrittenByteCountListener
- callback to call when bytes are loaded- Returns:
- stdout from
docker
- Throws:
java.lang.InterruptedException
- if the 'docker load' process is interruptedjava.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 interfaceDockerClient
- Parameters:
imageReference
- the image to saveoutputPath
- the destination path to save the output tarballwrittenByteCountListener
- callback to call when bytes are saved- Throws:
java.lang.InterruptedException
- if the 'docker save' process is interruptedjava.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 interfaceDockerClient
- 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 ordocker inspect
failedjava.lang.InterruptedException
- if thedocker inspect
process was interrupted
-
-