public class DockerAccessWithHcClient extends Object implements DockerAccess
| Constructor and Description |
|---|
DockerAccessWithHcClient(String apiVersion,
String baseUrl,
String certPath,
int maxConnections,
Logger log)
Create a new access for the given URL
|
| Modifier and Type | Method and Description |
|---|---|
void |
buildImage(String image,
File dockerArchive,
boolean forceRemove,
boolean noCache)
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,
Arguments arguments)
Sets up an exec instance for a running container id
|
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.
|
boolean |
hasImage(String name)
Check whether the given name exists as image at the docker daemon
|
Container |
inspectContainer(String containerId)
Inspect a container
|
List<Container> |
listContainers(int limit)
List containers
|
void |
pullImage(String image,
AuthConfig authConfig,
String registry)
Pull an image from a remote registry and store it locally.
|
void |
pushImage(String image,
AuthConfig authConfig,
String registry)
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
|
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 id.
|
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 DockerAccessWithHcClient(String apiVersion, String baseUrl, String certPath, int maxConnections, Logger 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 informationIOExceptionpublic void startExecContainer(String containerId, LogOutputSpec outputSpec) throws DockerAccessException
DockerAccessstartExecContainer 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, 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, boolean forceRemove, boolean noCache) 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 buildforceRemove - whether to remove intermediate containersnoCache - whether to use cache when building the imageDockerAccessException - 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 useDockerAccessExceptionpublic 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 Container inspectContainer(String containerId) throws DockerAccessException
DockerAccessinspectContainer in interface DockerAccesscontainerId - container idContainerDetails representing the containerDockerAccessException - if the container could not be inspectedpublic List<Container> listContainers(int limit) throws DockerAccessException
DockerAccesslistContainers in interface DockerAccesslimit - limit of containers to listContainer objectsDockerAccessException - if the containers could not be listedpublic boolean hasImage(String name) throws DockerAccessException
DockerAccesshasImage in interface DockerAccessname - image name to checkDockerAccessExceptionpublic String getImageId(String name) throws DockerAccessException
DockerAccessnull if no such image existsgetImageId in interface DockerAccessname - name to lookupnullDockerAccessExceptionpublic 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 pullImage(String image, AuthConfig authConfig, String registry) 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.DockerAccessException - if the image couldn't be pulled.public void pushImage(String image, AuthConfig authConfig, String registry) throws DockerAccessException
DockerAccesspushImage in interface DockerAccessimage - image name to pushauthConfig - authentication configurationregistry - optional registry to which the image should be pushed.DockerAccessException - in case pushing failspublic 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 void start()
DockerAccessstart in interface DockerAccesspublic void shutdown()
DockerAccessshutdown in interface DockerAccessCopyright © 2016. All Rights Reserved.