Class DUUIDockerInterface

java.lang.Object
org.texttechnologylab.DockerUnifiedUIMAInterface.DUUIDockerInterface

public class DUUIDockerInterface extends Object
This is the general docker interface which interacts with the docker daemon.
  • Constructor Details

    • DUUIDockerInterface

      public DUUIDockerInterface() throws IOException
      Creates a default object which connects to the local docker daemon, may need admin rights depending on the docker installation Depending on the Operating System a different connection URI is used to build the DockerClient. On Windows the npipe protocol is required to establish a connection with the docker daemon.
      Throws:
      IOException
  • Method Details

    • extract_port_mapping

      public int extract_port_mapping(String containerid) throws InterruptedException
      Extracts port mapping from the container with the given containerid, this is important since docker does auto allocate ports when not explicitly specifying the port number. This will only work on a DockerWrapper constructed container.
      Parameters:
      containerid - The running containerid to read the port mapping from
      Returns:
      The port it was mapped to.
      Throws:
      InterruptedException
    • extract_port_mapping

      public int extract_port_mapping(String containerid, int portMapping) throws InterruptedException
      Extracts port mapping from the container with the given containerid, this is important since docker does auto allocate ports when not explicitly specifying the port number. This will only work on a DockerWrapper constructed container.
      Parameters:
      containerid - The running containerid to read the port mapping from
      Returns:
      The port it was mapped to.
      Throws:
      InterruptedException
    • extract_service_port_mapping

      public int extract_service_port_mapping(String service) throws InterruptedException
      Throws:
      InterruptedException
    • inside_container

      public boolean inside_container()
      Returns true if the code is run inside the container and false otherwise.
      Returns:
      true if in container false otherwise
    • get_ip

      public String get_ip()
      Reads the container gateway bridge ip if inside the container to enable communication between sibling containers or the localhost ip if one is the host.
      Returns:
      The ip address.
    • get_logs

      public String get_logs(String containerid) throws InterruptedException
      Reads the logs from the container to determine if the container has started up without errors
      Parameters:
      containerid - The container id to check the logs from
      Returns:
      The string representation of the read logs
      Throws:
      InterruptedException
    • stop_container

      public void stop_container(String id)
      Stops the container with the given container id
      Parameters:
      id - The id of the container to stop.
    • rm_service

      public void rm_service(String id)
      Stops the container with the given container id
      Parameters:
      id - The id of the container to stop.
    • export_to_new_image

      public void export_to_new_image(String containerid, String imagename)
      Exports a running container to a new image.
      Parameters:
      containerid - The containerid to commit to a new image
      imagename - The image name in the format "repository!imagename"
    • getLocalImage

      public com.github.dockerjava.api.model.Image getLocalImage(String imageName)
    • push_image

      public void push_image(String remoteName, String localName, String username, String password) throws InterruptedException
      Throws:
      InterruptedException
    • run_service

      public String run_service(String imagename, int scale) throws InterruptedException
      Throws:
      InterruptedException
    • run_service

      public String run_service(String imagename, int scale, List<String> constraints) throws InterruptedException
      Throws:
      InterruptedException
    • hasLocalImage

      public boolean hasLocalImage(String imageName)
    • getDockerClient

      public com.github.dockerjava.api.DockerClient getDockerClient()
    • build

      public String build(Path builddir, List<String> buildArgs)
    • isSwarmManagerNode

      public boolean isSwarmManagerNode()
    • pullImage

      public String pullImage(String tag) throws InterruptedException
      Throws:
      InterruptedException
    • pullImage

      public String pullImage(String tag, String username, String password) throws InterruptedException
      Throws:
      InterruptedException
    • pullImage

      public String pullImage(String tag, String username, String password, AtomicBoolean shutdown) throws InterruptedException
      Attempts to pull a docker image using its tag, and credentials if necessary.
      Parameters:
      tag - The unique identifier of the image (uri:version).
      username - Credentials username.
      password - Credentials password.
      shutdown - A flag to signal a pull cancel.
      Returns:
      The image tag.
      Throws:
      InterruptedException
    • getDigestFromImage

      public String getDigestFromImage(String imagename)
    • run

      public String run(String imageid, boolean gpu, boolean autoremove, int port, boolean mapDaemon) throws InterruptedException
      Builds and runs the container with a specified temporary build directory and some flags.
      Parameters:
      gpu - If the gpu should be used
      autoremove - If the autoremove flag is set for the container
      Returns:
      The docker container id
      Throws:
      InterruptedException
    • run

      public String run(String imageid, boolean gpu, boolean autoremove, int portContainer, int portHost, boolean mapDaemon) throws InterruptedException
      Builds and runs the container with a specified temporary build directory and some flags.
      Parameters:
      gpu - If the gpu should be used
      autoremove - If the autoremove flag is set for the container
      Returns:
      The docker container id
      Throws:
      InterruptedException