Class DockerService

java.lang.Object
io.micronaut.maven.services.DockerService

@Singleton public class DockerService extends Object
Provides methods to work with Docker images.
Since:
1.1
Author:
Álvaro Sánchez-Mariscal
  • Constructor Details

  • Method Details

    • buildImageCmd

      public com.github.dockerjava.api.command.BuildImageCmd buildImageCmd(String dockerfileName) throws IOException
      Parameters:
      dockerfileName - the name of the Dockerfile to load
      Returns:
      the BuildImageCmd by loading the given Dockerfile as classpath resource.
      Throws:
      IOException
    • buildImageCmd

      public com.github.dockerjava.api.command.BuildImageCmd buildImageCmd()
      Returns:
      a default BuildImageCmd.
    • buildImage

      public String buildImage(com.github.dockerjava.api.command.BuildImageCmd builder)
      Builds the Docker image from the given BuildImageCmd builder.
      Parameters:
      builder - The builder to use.
      Returns:
      The resulting image ID.
    • runPrivilegedImageAndWait

      public void runPrivilegedImageAndWait(String imageId, Integer timeoutSeconds, String checkpointNetworkName, String... binds) throws IOException
      Creates a container based on a given image, and runs it.
      Parameters:
      imageId - the image to use
      timeoutSeconds - the timeout in seconds for the container to finish execution
      checkpointNetworkName - the name of the network to use for the container
      binds - the bind mounts to use
      Throws:
      IOException
    • copyFromContainer

      public File copyFromContainer(String imageId, String containerPath)
      Copies a file from the specified container path in the given image ID, into a temporal location.
      Parameters:
      imageId - The image ID.
      containerPath - The container path.
      Returns:
      The temporal file.
    • loadDockerfileAsResource

      Loads the given Dockerfile as classpath resource and copies it into a temporary location in the target directory.
      Parameters:
      name - the name of the Dockerfile.
      Returns:
      the file where the Dockerfile was copied to.
      Throws:
      IOException
    • loadDockerfileAsResource

      public File loadDockerfileAsResource(String name, String targetFileName) throws IOException
      Loads the given Dockerfile as classpath resource and copies it into a temporary location in the target directory.
      Parameters:
      name - the name of the Dockerfile.
      targetFileName - the name of the file to copy the Dockerfile to.
      Returns:
      the file where the Dockerfile was copied to.
      Throws:
      IOException
    • pushImageCmd

      public com.github.dockerjava.api.command.PushImageCmd pushImageCmd(String imageName)
      Parameters:
      imageName - the image name
      Returns:
      a PushImageCmd from the given image name.
    • getAuthConfigFor

      public com.github.dockerjava.api.model.AuthConfig getAuthConfigFor(String dockerImage, String username, String password)
      Parameters:
      dockerImage - the image name
      username - the username
      password - the password
      Returns:
      an AuthConfig object for the given image, username and password.