Interface IDockerContainer


public interface IDockerContainer
Docker Container Resource Object Provides a resource object representing a Docker Container on a Docker Engine. The normal method of obtaining a Docker Container resource object is by using a field:-
@DockerContainer(dockerContainerTag="a", image="galasadocker/ivp:1.0.0")
private IDockerContainer containerA;

The following are DSE Environment properties:-
docker.container.TAG.name=BOB to define the name the container is to use.
docker.container.TAG.leave.running=true to inform the DSE that the container is not to be killed at startup or stopped once the test is complete.
docker.engine=http://localhost:2375 the Docker Server/Swarm the container is to run on.
docker.registries=http://localhost:5000 a list of Docker registries to search for an image
  • Method Details

    • getDockerImage

      IDockerImage getDockerImage()
      Fetch the Resource Object representing the Docker Image of this container.
      Returns:
      a IDockerImage for this container - never null
    • getExposedPorts

      Returns a map of all the exposed ports of the container and the real host ports they have been mapped to. An exposed port can be mapped to more than one host port. The exposed port in the format used by docker, eg if tcp port 80 is exposed by the image, then the port will be mapped to "tcp/80". The InetSocketAddress will contain the ip address of the host.
      Returns:
      a map of the exposed ports, never null
      Throws:
      DockerManagerException
    • getFirstSocketForExposedPort

      InetSocketAddress getFirstSocketForExposedPort(String exposedPort)
      A convenience method to obtain the first socket of an exposed port. Normally an exposed port will only have one real socket, so this will usual way of obtaining the socket of an exposed port.
      Parameters:
      exposedPort - - the name of the exposed port - eg "tcp/80"
      Returns:
      InetSocketAddress of the first real port, or null if not exposed or not mapped
    • getRandomSocketForExposedPort

      InetSocketAddress getRandomSocketForExposedPort(String exposedPort)
      A convenience method to obtain a random socket for an exposed port that has been mapped to more than one host socket. Similar to getFirstSocketForExposedPort(String).
      Parameters:
      exposedPort - - the name of the exposed port - eg "tcp/80"
      Returns:
      InetSocketAddress of a random real port, or null if not exposed or not mapped
    • start

      void start() throws DockerManagerException
      Start the Docker Container. The Docker Manager does not validate that the container is down, so if up it will throw an exception with the remote api failure, likely to be NOT MODIFIED.
      Throws:
      DockerManagerException
    • startWithConfig

      void startWithConfig(IDockerContainerConfig config) throws DockerManagerException
      Start the Docker Container with a provided galasa DockerContainerConfig. This will stop and remove any previous containers.
      Parameters:
      config -
      Throws:
      DockerManagerException
    • stop

      void stop() throws DockerManagerException
      Stop the Docker Container. The Docker Manager does not validate that the container is up, so if down it will throw an exception with the remote api failure, likely to be NOT MODIFIED.
      Throws:
      DockerManagerException
    • exec

      IDockerExec exec(String... command) throws DockerManagerException
      Equivalent to exec(defaultResourceTimeout, commands...);
      Parameters:
      command - - An array of command and its parameters
      Returns:
      Throws:
      DockerManagerException
    • exec

      IDockerExec exec(int timeout, String... command) throws DockerManagerException
      Issue a command to a running container. Will return a IDockerExec resource object. The command will continue to execute in the background.
      Use:-
      container.exec("ls","-l","/var/log");
      Parameters:
      timeout - - A timeout in milliseconds for the command to send output
      command - - An array of command and its parameters
      Returns:
      IDockerExec
      Throws:
      DockerManagerException
    • retrieveStdOut

      String retrieveStdOut() throws DockerManagerException
      Retrieve the full STDOUT for the Docker Container
      Returns:
      Full Container STDOUT contents
      Throws:
      DockerManagerException
    • retrieveStdErr

      String retrieveStdErr() throws DockerManagerException
      Retrieve the full STDERR for the Docker Container
      Returns:
      Full Container STDERR contents
      Throws:
      DockerManagerException
    • isRunning

      boolean isRunning() throws DockerManagerException
      Checks with the docker engine to find the running state of this container.
      Returns:
      boolean
      Throws:
      DockerManagerException
    • getExitCode

      long getExitCode() throws DockerManagerException
      Retireves the exit code from the container
      Returns:
      long
      Throws:
      DockerManagerException
    • storeFile

      void storeFile(String absolutePath, InputStream file) throws DockerManagerException
      Stores a file onto the container. Path must be fully qualified including the name of the file on the container.
      Parameters:
      absolutePath -
      file -
      Throws:
      DockerManagerException
    • retrieveFile

      InputStream retrieveFile(String path) throws DockerManagerException
      Retreievs a InputStream of a file on the container.
      Parameters:
      path -
      Returns:
      Throws:
      DockerManagerException
    • retrieveFileAsString

      String retrieveFileAsString(String path) throws DockerManagerException
      Retrieves a file from the container and passes the contents back as a string.
      Parameters:
      path -
      Returns:
      String
      Throws:
      DockerManagerException