public class DockerAccessWithHcClient extends Object implements DockerAccess
The design goal here is to provide only the functionality required for this plugin in order to make it as robust as possible against docker API changes (which happen quite frequently). That's also the reason, why no framework like JAX-RS or docker-java is used so that the dependencies are kept low.
Of course, it's a bit more manual work, but it's worth the effort (as long as the Docker API functionality required is not too much).| Modifier and Type | Field and Description |
|---|---|
static String |
API_VERSION |
| Constructor and Description |
|---|
DockerAccessWithHcClient(String baseUrl,
String certPath,
int maxConnections,
org.eclipse.jkube.kit.common.KitLogger log)
Create a new access for the given URL
|
| Modifier and Type | Method and Description |
|---|---|
void |
buildImage(String image,
File dockerArchive,
BuildOptions options)
Create an docker image from a given archive
|
void |
copyArchive(String containerId,
File archive,
String targetPath)
Copy an archive (must be a tar) into a running container
Get all containers matching a certain label.
|
String |
createContainer(ContainerCreateConfig containerConfig,
String containerName)
Create a container from the given image.
|
String |
createExecContainer(String containerId,
org.eclipse.jkube.kit.common.Arguments arguments)
Sets up an exec instance for a running container id
|
String |
createNetwork(NetworkCreateConfig networkConfig)
Create a custom network from the given configuration.
|
String |
createVolume(VolumeCreateConfig containerConfig)
Create a volume
|
String |
fetchApiVersionFromServer(String baseUrl,
ApacheHttpClientDelegate delegate) |
ContainerDetails |
getContainer(String containerIdOrName)
Get a container
|
List<Container> |
getContainersForImage(String image,
boolean all)
Get all containers which are build from an image.
|
ExecDetails |
getExecContainer(String containerIdOrName)
Get an exec container which is the result of executing a command in a running container.
|
String |
getImageId(String name)
Get the image id of a given name or
null if no such image exists |
LogGetHandle |
getLogAsync(String containerId,
LogCallback callback)
Get logs asynchronously.
|
void |
getLogSync(String containerId,
LogCallback callback)
Get logs for a container up to now synchronously.
|
String |
getServerApiVersion()
Get the API version of the running server
|
boolean |
hasImage(String name)
Check whether the given name exists as image at the docker daemon
|
List<Network> |
listNetworks()
List all networks
|
void |
loadImage(String image,
File tarArchive)
Load an image from an archive.
|
void |
pullImage(String image,
AuthConfig authConfig,
String registry,
CreateImageOptions options)
Pull an image from a remote registry and store it locally.
|
void |
pushImage(String image,
AuthConfig authConfig,
String registry,
int retries)
Push an image to a registry.
|
void |
removeContainer(String containerId,
boolean removeVolumes)
Remove a container with the given id
|
boolean |
removeImage(String image,
boolean... forceOpt)
Remove an image from this docker installation
|
boolean |
removeNetwork(String networkId)
Remove a custom network
|
void |
removeVolume(String name)
Removes a volume.
|
void |
saveImage(String image,
String filename,
org.eclipse.jkube.kit.common.archive.ArchiveCompression compression)
Save an image to a tar file
|
void |
shutdown()
Lifecycle method which must be called when this object is not needed anymore.
|
void |
start()
Lifecycle method for this access class which must be called before any other method is called.
|
void |
startContainer(String containerId)
Start a container.
|
void |
startExecContainer(String containerId,
LogOutputSpec outputSpec)
Starts a previously set up exec instance (via
DockerAccess.createExecContainer(String, Arguments) container
this API sets up a session with the exec command. |
void |
stopContainer(String containerId,
int killWait)
Stop a container.
|
void |
tag(String sourceImage,
String targetImage,
boolean force)
Alias an image in the repository with a complete new name.
|
public static final String API_VERSION
public DockerAccessWithHcClient(String baseUrl, String certPath, int maxConnections, org.eclipse.jkube.kit.common.KitLogger log) throws IOException
baseUrl - base URL for accessing the docker DaemoncertPath - used to build up a keystore with the given keys and certificates found in this
directorymaxConnections - maximum parallel connections allowed to docker daemon (if a pool is used)log - a log handler for printing out logging informationIOException - in case of I/O exceptionpublic String getServerApiVersion() throws DockerAccessException
getServerApiVersion in interface DockerAccessDockerAccessException - if the api version could not be obtainedpublic void startExecContainer(String containerId, LogOutputSpec outputSpec) throws DockerAccessException
DockerAccessDockerAccess.createExecContainer(String, Arguments) container
this API sets up a session with the exec command. Output is streamed to the log. This methods
returns only when the exec command has finished (i.e this method calls the command in a non-detached mode).startExecContainer in interface DockerAccesscontainerId - id of the exec containeroutputSpec - how to print out the output of the commandDockerAccessException - if the container could not be created.public String createExecContainer(String containerId, org.eclipse.jkube.kit.common.Arguments arguments) throws DockerAccessException
DockerAccesscreateExecContainer in interface DockerAccesscontainerId - id of the running container which the exec container will be created forarguments - container exec commands to runDockerAccessException - if the container could not be created.public String createContainer(ContainerCreateConfig containerConfig, String containerName) throws DockerAccessException
DockerAccessThe container id will be set on the container upon successful creation.
createContainer in interface DockerAccesscontainerConfig - container configurationcontainerName - name container should be created with or null for a docker provided nameDockerAccessException - if the container could not be created.public void startContainer(String containerId) throws DockerAccessException
DockerAccessstartContainer in interface DockerAccesscontainerId - id of the container to startDockerAccessException - if the container could not be started.public void stopContainer(String containerId, int killWait) throws DockerAccessException
DockerAccessstopContainer in interface DockerAccesscontainerId - the container idkillWait - the time to wait between stop and kill (in seconds)DockerAccessException - if the container could not be stopped.public void buildImage(String image, File dockerArchive, BuildOptions options) throws DockerAccessException
DockerAccessbuildImage in interface DockerAccessimage - name of the image to build or null if none should be useddockerArchive - from which the docker image should be buildoptions - additional query arguments to add when building the image. Can be null.DockerAccessException - if docker host reports an error during building of an imagepublic void copyArchive(String containerId, File archive, String targetPath) throws DockerAccessException
DockerAccesscopyArchive in interface DockerAccesscontainerId - container to copy intoarchive - local archive to copy intotargetPath - target path to useDockerAccessException - if the archive could not be copiedpublic void getLogSync(String containerId, LogCallback callback)
DockerAccessgetLogSync in interface DockerAccesscontainerId - container idcallback - which is called for each line receivedpublic LogGetHandle getLogAsync(String containerId, LogCallback callback)
DockerAccessgetLogAsync in interface DockerAccesscontainerId - id of the container for which to fetch the logscallback - to call when log data arrivespublic List<Container> getContainersForImage(String image, boolean all) throws DockerAccessException
DockerAccessgetContainersForImage in interface DockerAccessimage - for which its container are looked upall - whether to fetch also stopped containers. If false only running containers are returnedContainer objects or an empty list if none is foundDockerAccessException - if the request failspublic ContainerDetails getContainer(String containerIdOrName) throws DockerAccessException
DockerAccessgetContainer in interface DockerAccesscontainerIdOrName - container id or nameContainerDetails representing the container or null if none could be foundDockerAccessException - if the container could not be inspectedpublic ExecDetails getExecContainer(String containerIdOrName) throws DockerAccessException
DockerAccessgetExecContainer in interface DockerAccesscontainerIdOrName - exec container id or nameExecDetails representing the container or null if none could be foundDockerAccessException - if the container could not be inspectedpublic boolean hasImage(String name) throws DockerAccessException
DockerAccesshasImage in interface DockerAccessname - image name to checkDockerAccessException - docker access exceptionpublic String getImageId(String name) throws DockerAccessException
DockerAccessnull if no such image existsgetImageId in interface DockerAccessname - name to lookupnullDockerAccessException - docker access exceptionpublic void removeContainer(String containerId, boolean removeVolumes) throws DockerAccessException
DockerAccessremoveContainer in interface DockerAccesscontainerId - container id for the container to removeremoveVolumes - if true, will remove any volumes associated to containerDockerAccessException - if the container couldn't be removed.public void loadImage(String image, File tarArchive) throws DockerAccessException
DockerAccessloadImage in interface DockerAccessimage - the image to pull.tarArchive - archive fileDockerAccessException - if the image couldn't be loaded.public void pullImage(String image, AuthConfig authConfig, String registry, CreateImageOptions options) throws DockerAccessException
DockerAccesspullImage in interface DockerAccessimage - the image to pull.authConfig - authentication configuration used when pulling an imageregistry - an optional registry from where to pull the image. Can be null.options - additional query arguments to add when creating the image. Can be null.DockerAccessException - if the image couldn't be pulled.public void pushImage(String image, AuthConfig authConfig, String registry, int retries) throws DockerAccessException
DockerAccesspushImage in interface DockerAccessimage - image name to pushauthConfig - authentication configurationregistry - optional registry to which the image should be pushed.retries - optional number of times the push should be retried on a 500 errorDockerAccessException - in case pushing failspublic void saveImage(String image, String filename, org.eclipse.jkube.kit.common.archive.ArchiveCompression compression) throws DockerAccessException
DockerAccesssaveImage in interface DockerAccessimage - image to savefilename - target filenamecompression - compression to use for the archiveDockerAccessException - if an image cannot be removedpublic void tag(String sourceImage, String targetImage, boolean force) throws DockerAccessException
DockerAccesstag in interface DockerAccesssourceImage - full name (including tag) of the image to aliastargetImage - the alias nameforce - forced taggingDockerAccessException - if the original image doesn't exist or another error occurs somehow.public boolean removeImage(String image, boolean... forceOpt) throws DockerAccessException
DockerAccessremoveImage in interface DockerAccessimage - image to removeforceOpt - if set to true remove containers as well (only the first vararg is evaluated)DockerAccessException - if an image cannot be removedpublic List<Network> listNetworks() throws DockerAccessException
DockerAccesslistNetworks in interface DockerAccessNetwork objectsDockerAccessException - if the networks could not be listedpublic String createNetwork(NetworkCreateConfig networkConfig) throws DockerAccessException
DockerAccesscreateNetwork in interface DockerAccessnetworkConfig - network configurationDockerAccessException - if the container could not be created.public boolean removeNetwork(String networkId) throws DockerAccessException
DockerAccessremoveNetwork in interface DockerAccessnetworkId - network to removeDockerAccessException - if an image cannot be removedpublic String createVolume(VolumeCreateConfig containerConfig) throws DockerAccessException
DockerAccesscreateVolume in interface DockerAccesscontainerConfig - volume configurationDockerAccessException - if the volume could not be created.public void removeVolume(String name) throws DockerAccessException
DockerAccessremoveVolume in interface DockerAccessname - volume name to removeDockerAccessException - if the volume could not be removedpublic void start()
DockerAccessstart in interface DockerAccesspublic void shutdown()
DockerAccessshutdown in interface DockerAccesspublic String fetchApiVersionFromServer(String baseUrl, ApacheHttpClientDelegate delegate) throws IOException
IOExceptionCopyright © 2023. All rights reserved.