Package io.fabric8.maven.docker.access
Interface DockerAccess
-
- All Known Implementing Classes:
DockerAccessWithHcClient
public interface DockerAccessAccess to the Docker API which provides the methods needed bu this maven plugin.- Since:
- 04.04.14
- Author:
- roland
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbuildImage(String image, File dockerArchive, BuildOptions options)Create an docker image from a given archivevoidcopyArchiveFromContainer(String containerId, String containerPath, File archive)Copy file or directory from container as a tar archive.voidcopyArchiveToContainer(String containerId, File archive, String targetPath)Copy an archive (must be a tar) into a running container.StringcreateContainer(ContainerCreateConfig configuration, String containerName)Create a container from the given image.StringcreateExecContainer(String containerId, Arguments arguments)Sets up an exec instance for a running container idStringcreateNetwork(NetworkCreateConfig configuration)Create a custom network from the given configuration.StringcreateVolume(VolumeCreateConfig configuration)Create a volumeContainerDetailsgetContainer(String containerIdOrName)Get a containerList<Container>getContainersForImage(String image, boolean all)Get all containers which are build from an image.ExecDetailsgetExecContainer(String containerIdOrName)Get an exec container which is the result of executing a command in a running container.StringgetImageId(String name)Get the image id of a given name ornullif no such image existsList<String>getImageTags(String name)Get the list of tags of a given image name ornullif no such image existsLogGetHandlegetLogAsync(String containerId, LogCallback callback)Get logs asynchronously.voidgetLogSync(String containerId, LogCallback callback)Get logs for a container up to now synchronously.StringgetServerApiVersion()Get the API version of the running serverbooleanhasImage(String name)Check whether the given name exists as image at the docker daemonvoidkillContainer(String containerId)Kill a containerList<Container>listContainers(boolean all)List all containers from the Docker server.List<Image>listImages(boolean all)List the containers on the serverList<Network>listNetworks()List all networksvoidloadImage(String image, File tarArchive)Load an image from an archive.voidpullImage(String image, AuthConfig authConfig, String registry, CreateImageOptions options)Pull an image from a remote registry and store it locally.voidpushImage(String image, AuthConfig authConfig, String registry, int retries)Push an image to a registry.voidremoveContainer(String containerId, boolean removeVolumes)Remove a container with the given idbooleanremoveImage(String image, boolean... force)Remove an image from this docker installationbooleanremoveNetwork(String networkId)Remove a custom networkvoidremoveVolume(String name)Removes a volume.voidsaveImage(String image, String filename, ArchiveCompression compression)Save an image to a tar filevoidshutdown()Lifecycle method which must be called when this object is not needed anymore.voidstart()Lifecycle method for this access class which must be called before any other method is called.voidstartContainer(String containerId)Start a container.voidstartExecContainer(String containerId, LogOutputSpec outputSpec)Starts a previously set up exec instance (viacreateExecContainer(String, Arguments)container this API sets up a session with the exec command.voidstopContainer(String containerId, int killWait)Stop a container.voidtag(String sourceImage, String targetImage, boolean force)Alias an image in the repository with a complete new name.
-
-
-
Method Detail
-
getServerApiVersion
String getServerApiVersion() throws DockerAccessException
Get the API version of the running server- Returns:
- api version in the form "1.24"
- Throws:
DockerAccessException- if the api version could not be obtained
-
getContainer
ContainerDetails getContainer(String containerIdOrName) throws DockerAccessException
Get a container- Parameters:
containerIdOrName- container id or name- Returns:
ContainerDetailsrepresenting the container or null if none could be found- Throws:
DockerAccessException- if the container could not be inspected
-
getExecContainer
ExecDetails getExecContainer(String containerIdOrName) throws DockerAccessException
Get an exec container which is the result of executing a command in a running container.- Parameters:
containerIdOrName- exec container id or name- Returns:
ExecDetailsrepresenting the container or null if none could be found- Throws:
DockerAccessException- if the container could not be inspected
-
hasImage
boolean hasImage(String name) throws DockerAccessException
Check whether the given name exists as image at the docker daemon- Parameters:
name- image name to check- Returns:
- true if the image exists
- Throws:
DockerAccessException
-
getImageId
String getImageId(String name) throws DockerAccessException
Get the image id of a given name ornullif no such image exists- Parameters:
name- name to lookup- Returns:
- the image id or
null - Throws:
DockerAccessException
-
getImageTags
List<String> getImageTags(String name) throws DockerAccessException
Get the list of tags of a given image name ornullif no such image exists- Parameters:
name- name to lookup- Returns:
- the list of image tags or
null - Throws:
DockerAccessException
-
listContainers
List<Container> listContainers(boolean all) throws DockerAccessException
List all containers from the Docker server.- Parameters:
all- whether to fetch also stopped containers. If false only running containers are returned- Returns:
- list of
Containerobjects or an empty list if none is found - Throws:
DockerAccessException- if the request fails
-
getContainersForImage
List<Container> getContainersForImage(String image, boolean all) throws DockerAccessException
Get all containers which are build from an image. By default only the last containers are considered but this can be tuned with a global parameters.- Parameters:
image- for which its container are looked upall- whether to fetch also stopped containers. If false only running containers are returned- Returns:
- list of
Containerobjects or an empty list if none is found - Throws:
DockerAccessException- if the request fails
-
startExecContainer
void startExecContainer(String containerId, LogOutputSpec outputSpec) throws DockerAccessException
Starts a previously set up exec instance (viacreateExecContainer(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).- Parameters:
containerId- id of the exec containeroutputSpec- how to print out the output of the command- Throws:
DockerAccessException- if the container could not be created.
-
createExecContainer
String createExecContainer(String containerId, Arguments arguments) throws DockerAccessException
Sets up an exec instance for a running container id- Parameters:
containerId- id of the running container which the exec container will be created forarguments- container exec commands to run- Throws:
DockerAccessException- if the container could not be created.
-
createContainer
String createContainer(ContainerCreateConfig configuration, String containerName) throws DockerAccessException
Create a container from the given image.The
container idwill be set on thecontainerupon successful creation.- Parameters:
configuration- container configurationcontainerName- name container should be created with ornullfor a docker provided name- Throws:
DockerAccessException- if the container could not be created.
-
startContainer
void startContainer(String containerId) throws DockerAccessException
Start a container.- Parameters:
containerId- id of the container to start- Throws:
DockerAccessException- if the container could not be started.
-
stopContainer
void stopContainer(String containerId, int killWait) throws DockerAccessException
Stop a container.- Parameters:
containerId- the container idkillWait- the time to wait between stop and kill (in seconds)- Throws:
DockerAccessException- if the container could not be stopped.
-
killContainer
void killContainer(String containerId) throws DockerAccessException
Kill a container- Parameters:
containerId- the container id- Throws:
DockerAccessException- if container failed to be killed
-
copyArchiveToContainer
void copyArchiveToContainer(String containerId, File archive, String targetPath) throws DockerAccessException
Copy an archive (must be a tar) into a running container.- Parameters:
containerId- container to copy intoarchive- local archive to copy intotargetPath- target path to use- Throws:
DockerAccessException- if the archive could not be copied
-
copyArchiveFromContainer
void copyArchiveFromContainer(String containerId, String containerPath, File archive) throws DockerAccessException
Copy file or directory from container as a tar archive.- Parameters:
containerId- container to copy fromcontainerPath- source path of a container to copyarchive- local tar archive to copy into- Throws:
DockerAccessException- if the archive could not be copied
-
getLogSync
void getLogSync(String containerId, LogCallback callback)
Get logs for a container up to now synchronously.- Parameters:
containerId- container idcallback- which is called for each line received
-
getLogAsync
LogGetHandle getLogAsync(String containerId, LogCallback callback)
Get logs asynchronously. This call will start a thread in the background for doing the request. It returns a handle which can be used to abort the request on demand.- Parameters:
containerId- id of the container for which to fetch the logscallback- to call when log data arrives- Returns:
- handle for managing the lifecycle of the thread
-
removeContainer
void removeContainer(String containerId, boolean removeVolumes) throws DockerAccessException
Remove a container with the given id- Parameters:
containerId- container id for the container to removeremoveVolumes- if true, will remove any volumes associated to container- Throws:
DockerAccessException- if the container couldn't be removed.
-
listImages
List<Image> listImages(boolean all) throws DockerAccessException
List the containers on the server- Parameters:
all- if true, return untagged images- Returns:
- the images list (may be empty but never null)
- Throws:
DockerAccessException- if the list couldn't be retrieved
-
loadImage
void loadImage(String image, File tarArchive) throws DockerAccessException
Load an image from an archive.- Parameters:
image- the image to pull.tarArchive- archive file- Throws:
DockerAccessException- if the image couldn't be loaded.
-
pullImage
void pullImage(String image, AuthConfig authConfig, String registry, CreateImageOptions options) throws DockerAccessException
Pull an image from a remote registry and store it locally.- Parameters:
image- 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.- Throws:
DockerAccessException- if the image couldn't be pulled.
-
pushImage
void pushImage(String image, AuthConfig authConfig, String registry, int retries) throws DockerAccessException
Push an image to a registry. An registry can be specified which is used as target if the image name the image does not contain a registry. If an optional registry is used, the image is also tagged with the full name containing the registry as part (if not already existent)- Parameters:
image- 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 error- Throws:
DockerAccessException- in case pushing fails
-
buildImage
void buildImage(String image, File dockerArchive, BuildOptions options) throws DockerAccessException
Create an docker image from a given archive- Parameters:
image- name of the image to build ornullif none should be useddockerArchive- from which the docker image should be buildoptions- additional query arguments to add when building the image. Can be null.- Throws:
DockerAccessException- if docker host reports an error during building of an image
-
tag
void tag(String sourceImage, String targetImage, boolean force) throws DockerAccessException
Alias an image in the repository with a complete new name. (Note that this maps to a Docker Remote API 'tag' operation, which IMO is badly named since it also can generate a complete alias to a given image)- Parameters:
sourceImage- full name (including tag) of the image to aliastargetImage- the alias nameforce- forced tagging- Throws:
DockerAccessException- if the original image doesn't exist or another error occurs somehow.
-
removeImage
boolean removeImage(String image, boolean... force) throws DockerAccessException
Remove an image from this docker installation- Parameters:
image- image to removeforce- if set to true remove containers as well (only the first vararg is evaluated)- Returns:
- true if an image was removed, false if none was removed
- Throws:
DockerAccessException- if an image cannot be removed
-
saveImage
void saveImage(String image, String filename, ArchiveCompression compression) throws DockerAccessException
Save an image to a tar file- Parameters:
image- image to savefilename- target filenamecompression- compression to use for the archive- Throws:
DockerAccessException- if an image cannot be removed
-
listNetworks
List<Network> listNetworks() throws DockerAccessException
List all networks- Returns:
- list of
Networkobjects - Throws:
DockerAccessException- if the networks could not be listed
-
createNetwork
String createNetwork(NetworkCreateConfig configuration) throws DockerAccessException
Create a custom network from the given configuration.- Parameters:
configuration- network configuration- Throws:
DockerAccessException- if the container could not be created.
-
removeNetwork
boolean removeNetwork(String networkId) throws DockerAccessException
Remove a custom network- Parameters:
networkId- network to remove- Returns:
- true if an network was removed, false if none was removed
- Throws:
DockerAccessException- if an image cannot be removed
-
start
void start() throws DockerAccessExceptionLifecycle method for this access class which must be called before any other method is called.- Throws:
DockerAccessException
-
shutdown
void shutdown()
Lifecycle method which must be called when this object is not needed anymore. This hook might be used for cleaning up things.
-
createVolume
String createVolume(VolumeCreateConfig configuration) throws DockerAccessException
Create a volume- Parameters:
configuration- volume configuration- Returns:
- the name of the Volume
- Throws:
DockerAccessException- if the volume could not be created.
-
removeVolume
void removeVolume(String name) throws DockerAccessException
Removes a volume. It is a no-op if the volume does not exist.- Parameters:
name- volume name to remove- Throws:
DockerAccessException- if the volume could not be removed
-
-