Class ContainerUtils

java.lang.Object
org.aksw.commons.util.docker.ContainerUtils

public class ContainerUtils extends Object
  • Constructor Details

    • ContainerUtils

      public ContainerUtils()
  • Method Details

    • setGlobalRetryCountIfAbsent

      public static void setGlobalRetryCountIfAbsent(int retryCount)
    • toBindMode

      public static org.testcontainers.containers.BindMode toBindMode(com.github.dockerjava.api.model.AccessMode am)
    • getUserString

      public static String getUserString() throws IOException
      Throws:
      IOException
    • getExitValueLong

      public static long getExitValueLong(org.testcontainers.containers.GenericContainer<?> container)
      Get the exit value based on the container's info. This will only work if the container has been stopped but not removed.
    • getExitValue

      public static int getExitValue(org.testcontainers.containers.GenericContainer<?> container)
    • waitFor

      public static void waitFor(org.testcontainers.containers.GenericContainer<?> container) throws InterruptedException
      Throws:
      InterruptedException
    • findSelfByHostname

      public static com.github.dockerjava.api.command.InspectContainerResponse findSelfByHostname(com.github.dockerjava.api.DockerClient docker)
      Find and inspect the container that matches this process's hostname.
      Returns:
      InspectContainerResponse of the matching container or null if none found.
      Throws:
      IOException - if /etc/hostname can't be read
    • detectContainer

      public static com.github.dockerjava.api.command.InspectContainerResponse detectContainer(com.github.dockerjava.api.DockerClient dockerClient)
    • addCurrentUserAndGroup

      public static <T extends org.testcontainers.containers.GenericContainer<T>> org.testcontainers.containers.GenericContainer<T> addCurrentUserAndGroup(org.testcontainers.containers.GenericContainer<T> container) throws IOException
      Throws:
      IOException
    • checkImageForCommand

      public static String checkImageForCommand(String imageName, String commandName)
      Check whether a command exists in an image and return its path. Null if not found.
    • checkImage

      public static String checkImage(String imageName, String entryPoint, String whichCommand, String commandName)
    • canRunEntrypoint

      public static boolean canRunEntrypoint(String imageName, String entrypoint, String... commandPrefix)
    • canRunEntrypoint

      public static boolean canRunEntrypoint(String imageName, String entrypoint, List<String> commandPrefix)
    • hasCommand

      public static boolean hasCommand(String imageName, String entrypoint, List<String> commandPrefix, String command)
    • runCommand

      public static int runCommand(String imageName, String entrypoint, List<String> commandPrefix, String... command)
    • runCommand

      public static int runCommand(String imageName, String entrypoint, List<String> commandPrefix, List<String> command)
    • newInputStream

      public static InputStream newInputStream(org.testcontainers.containers.GenericContainer<?> container)
      Starts a container and returns an input stream over its output. Closing the input stream terminates the container.
      Parameters:
      container - A container that has not yet been started.
      Returns:
      An input stream over the container's output (STDOUT).
    • fileExistsInImage

      public boolean fileExistsInImage(String imageName, String pathInContainer)
      Check if a path exists in the filesystem of the given image, without starting a container. Relies on opening an input stream to the targe file via copyArchiveFromContainerCmd.