Class 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
    • Method Summary

      Modifier and Type Method Description
      static Container createLocalstackContainer​(java.lang.String externalHostName, boolean pullNewImage, boolean randomizePorts, java.lang.String imageTag, java.util.Map<java.lang.String,​java.lang.String> environmentVariables)
      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
      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 Detail

      • LOCALSTACK_EXTERNAL_HOSTNAME

        public static final java.lang.String LOCALSTACK_EXTERNAL_HOSTNAME
        See Also:
        Constant Field Values
    • Method Detail

      • createLocalstackContainer

        public static Container createLocalstackContainer​(java.lang.String externalHostName,
                                                          boolean pullNewImage,
                                                          boolean randomizePorts,
                                                          java.lang.String imageTag,
                                                          java.util.Map<java.lang.String,​java.lang.String> environmentVariables)
        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
        environmentVariables - map of environment variables to be passed to the docker container
      • 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)
      • 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