Class Container

java.lang.Object
cloud.localstack.docker.Container

public class Container
extends java.lang.Object
An abstraction of the LocalStack docker container. Provides port mappings, a way to poll the logs until a specified token appears, and the ability to stop the container.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String LOCALSTACK_EXTERNAL_HOSTNAME  
  • Method Summary

    Modifier and Type Method Description
    static Container createLocalstackContainer​(java.lang.String externalHostName, boolean pullNewImage, boolean randomizePorts, java.lang.String imageName, java.lang.String imageTag, java.lang.String portEdge, java.lang.String portElasticSearch, java.util.Map<java.lang.String,​java.lang.String> environmentVariables, java.util.Map<java.lang.Integer,​java.lang.Integer> portMappings, java.util.Map<java.lang.String,​java.lang.String> bindMounts, java.lang.String platform)
    It creates a container using the hostname given and the set of environment variables provided
    java.lang.String executeCommand​(java.util.List<java.lang.String> command)
    Run a command on the container via docker exec
    int getExternalPortFor​(int internalPort)
    Given an internal port, retrieve the publicly addressable port that maps to it
    static Container getRunningLocalstackContainer()  
    static Container getRunningLocalstackContainer​(java.lang.String containerId)  
    boolean isRunning()  
    void stop()
    Stop the container
    void waitForAllPorts​(java.lang.String ip)  
    void waitForLogToken​(java.util.regex.Pattern pattern)
    Poll the docker logs until a specific token appears, then return.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • createLocalstackContainer

      public static Container createLocalstackContainer​(java.lang.String externalHostName, boolean pullNewImage, boolean randomizePorts, java.lang.String imageName, java.lang.String imageTag, java.lang.String portEdge, java.lang.String portElasticSearch, java.util.Map<java.lang.String,​java.lang.String> environmentVariables, java.util.Map<java.lang.Integer,​java.lang.Integer> portMappings, java.util.Map<java.lang.String,​java.lang.String> bindMounts, java.lang.String platform)
      It creates a container using the hostname given and the set of environment variables provided
      Parameters:
      externalHostName - hostname to be used by localstack
      pullNewImage - determines if docker pull should be run to update to the latest image of the container
      randomizePorts - determines if the container should expose the default local stack ports or if it should expose randomized ports in order to prevent conflicts with other localstack containers running on the same machine
      imageName - the name of the image defaults to "localstack/localstack" if null
      imageTag - the tag of the image to pull, defaults to "latest" if null
      environmentVariables - map of environment variables to be passed to the docker container
      portMappings -
      bindMounts - Docker host to container volume mapping like /host/dir:/container/dir, be aware that the host directory must be an absolute path
      platform - target platform for the localstack docker image
    • getRunningLocalstackContainer

      public static Container getRunningLocalstackContainer()
    • getRunningLocalstackContainer

      public static Container getRunningLocalstackContainer​(java.lang.String containerId)
    • getExternalPortFor

      public int getExternalPortFor​(int internalPort)
      Given an internal port, retrieve the publicly addressable port that maps to it
    • waitForAllPorts

      public void waitForAllPorts​(java.lang.String ip)
    • isRunning

      public boolean isRunning()
    • waitForLogToken

      public void waitForLogToken​(java.util.regex.Pattern pattern)
      Poll the docker logs until a specific token appears, then return. Primarily used to look for the "Ready." token in the LocalStack logs.
    • stop

      public void stop()
      Stop the container
    • executeCommand

      public java.lang.String executeCommand​(java.util.List<java.lang.String> command)
      Run a command on the container via docker exec