
io.fabric8.maven.docker.access.DockerAccess Maven / Gradle / Ivy
The newest version!
package io.fabric8.maven.docker.access;
import java.io.File;
import java.util.List;
import java.util.Map;
import io.fabric8.maven.docker.access.log.LogCallback;
import io.fabric8.maven.docker.access.log.LogGetHandle;
import io.fabric8.maven.docker.config.Arguments;
import io.fabric8.maven.docker.log.LogOutputSpec;
import io.fabric8.maven.docker.model.Container;
/**
* Access to the Docker API which
* provides the methods needed bu this maven plugin.
*
* @author roland
* @since 04.04.14
*/
public interface DockerAccess {
/**
* Inspect a container
*
* @param containerId container id
* @return ContainerDetails representing the container
* @throws DockerAccessException if the container could not be inspected
*/
Container inspectContainer(String containerId) throws DockerAccessException;
/**
* Check whether the given name exists as image at the docker daemon
*
* @param name image name to check
* @return true if the image exists
*/
boolean hasImage(String name) throws DockerAccessException;
/**
* Get the image id of a given name or null
if no such image exists
*
* @param name name to lookup
* @return the image id or null
*/
String getImageId(String name) throws DockerAccessException;
/**
* List containers
*
* @param limit limit of containers to list
* @return list of Container objects
* @throws DockerAccessException if the containers could not be listed
*/
List listContainers(int limit) throws DockerAccessException;
/**
* Starts a previously set up exec instance id.
* this API sets up an interactive session with the exec command. Output is streamed to the log.
*
* @param containerId id of the exec container
* @param outputSpec how to print out the output of the command
* @throws DockerAccessException if the container could not be created.
*/
void startExecContainer(String containerId, LogOutputSpec outputSpec) throws DockerAccessException;
/**
* Sets up an exec instance for a running container id
*
* @param containerId id of the running container which the exec container will be created for
* @param arguments container exec commands to run
* @throws DockerAccessException if the container could not be created.
*/
String createExecContainer(String containerId, Arguments arguments) throws DockerAccessException;
/**
* Create a container from the given image.
*
* The container id
will be set on the container
upon successful creation.
*
* @param configuration container configuration
* @param containerName name container should be created with or null
for a docker provided name
* @throws DockerAccessException if the container could not be created.
*/
String createContainer(ContainerCreateConfig configuration, String containerName) throws DockerAccessException;
/**
* Start a container.
*
* @param containerId id of the container to start
* @throws DockerAccessException if the container could not be started.
*/
void startContainer(String containerId) throws DockerAccessException;
/**
* Stop a container.
*
* @param containerId the container id
* @param killWait the time to wait between stop and kill (in seconds)
* @throws DockerAccessException if the container could not be stopped.
*/
void stopContainer(String containerId, int killWait) throws DockerAccessException;
/** Copy an archive (must be a tar) into a running container
* Get all containers matching a certain label. This might not be a cheap operation especially if many containers
* are running. Use with care.
*
* @param containerId container to copy into
* @param archive local archive to copy into
* @param targetPath target path to use
* @throws DockerAccessException
*/
void copyArchive(String containerId, File archive, String targetPath)
throws DockerAccessException;
/**
* Get logs for a container up to now synchronously.
*
* @param containerId container id
* @param callback which is called for each line received
*/
void getLogSync(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.
*
* @param containerId id of the container for which to fetch the logs
* @param callback to call when log data arrives
* @return handle for managing the lifecycle of the thread
*/
LogGetHandle getLogAsync(String containerId, LogCallback callback);
/**
* Remove a container with the given id
*
* @param containerId container id for the container to remove
* @param removeVolumes if true, will remove any volumes associated to container
* @throws DockerAccessException if the container couldn't be removed.
*/
void removeContainer(String containerId, boolean removeVolumes) throws DockerAccessException;
/**
* Pull an image from a remote registry and store it locally.
*
* @param image the image to pull.
* @param authConfig authentication configuration used when pulling an image
* @param registry an optional registry from where to pull the image. Can be null.
* @throws DockerAccessException if the image couldn't be pulled.
*/
void pullImage(String image, AuthConfig authConfig, String registry) 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)
*
* @param image image name to push
* @param authConfig authentication configuration
* @param registry optional registry to which the image should be pushed.
* @throws DockerAccessException in case pushing fails
*/
void pushImage(String image, AuthConfig authConfig, String registry) throws DockerAccessException;
/**
* Create an docker image from a given archive
*
* @param image name of the image to build or null
if none should be used
* @param dockerArchive from which the docker image should be build
* @param dockerfileName filename of the Dockerfile within the archive or null
for the default Dockerfile
* @param forceRemove whether to remove intermediate containers
* @param noCache whether to use cache when building the image
* @param buildArgs buildArgs to add then building the image. Can be null
for no build args. @throws DockerAccessException if docker host reports an error during building of an image
*/
void buildImage(String image, File dockerArchive, String dockerfileName, boolean forceRemove, boolean noCache,
Map buildArgs) 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)
*
* @param sourceImage full name (including tag) of the image to alias
* @param targetImage the alias name
* @param force forced tagging
* @throws DockerAccessException if the original image doesn't exist or another error occurs somehow.
*/
void tag(String sourceImage, String targetImage, boolean force) throws DockerAccessException;
/**
* Remove an image from this docker installation
*
* @param image image to remove
* @param force if set to true remove containers as well (only the first vararg is evaluated)
* @return true if an image was removed, false if none was removed
* @throws DockerAccessException if an image cannot be removed
*/
boolean removeImage(String image, boolean ... force) throws DockerAccessException;
/**
* Lifecycle method for this access class which must be called before any other method is called.
*/
void start() throws DockerAccessException;
/**
* Lifecycle method which must be called when this object is not needed anymore. This hook might be used for
* cleaning up things.
*/
void shutdown();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy