Interface DockerAccess

  • All Known Implementing Classes:
    DockerAccessWithHcClient

    public interface DockerAccess
    Access to the Docker API which provides the methods needed bu this maven plugin.
    Since:
    04.04.14
    Author:
    roland
    • Method Detail

      • getContainer

        ContainerDetails getContainer​(String containerIdOrName)
                               throws DockerAccessException
        Get a container
        Parameters:
        containerIdOrName - container id or name
        Returns:
        ContainerDetails representing 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:
        ExecDetails representing 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
      • 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 Container objects 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 up
        all - whether to fetch also stopped containers. If false only running containers are returned
        Returns:
        list of Container objects 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 (via 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).
        Parameters:
        containerId - id of the exec container
        outputSpec - 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 for
        arguments - 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 id will be set on the container upon successful creation.

        Parameters:
        configuration - container configuration
        containerName - name container should be created with or null for a docker provided name
        Throws:
        DockerAccessException - if the container could not be created.
      • stopContainer

        void stopContainer​(String containerId,
                           int killWait)
                    throws DockerAccessException
        Stop a container.
        Parameters:
        containerId - the container id
        killWait - the time to wait between stop and kill (in seconds)
        Throws:
        DockerAccessException - if the container could not be stopped.
      • 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 into
        archive - local archive to copy into
        targetPath - 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 from
        containerPath - source path of a container to copy
        archive - 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 id
        callback - 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 logs
        callback - 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 remove
        removeVolumes - 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
      • pullImage

        void pullImage​(String image,
                       AuthConfig authConfig,
                       String registry)
                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 image
        registry - an optional registry from where to pull 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 push
        authConfig - authentication configuration
        registry - 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 or null if none should be used
        dockerArchive - from which the docker image should be build
        options - 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 alias
        targetImage - the alias name
        force - 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 remove
        force - 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
      • 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
      • 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.
      • 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