title: Testcontainer's Redis container connects to a different container then the one defined in the test
body: <p>I'm doing integration tests in my Spring Boot app. The app needs a Redis to work with.</p>
  
  <p>During development phase, I have a local container of Redis that the app connects to.</p>
  
  <p>For the integration tests, I'm using <a href="https://www.testcontainers.org/" rel="noreferrer">testcontainers</a> and I also followed their <a href="https://www.testcontainers.org/usage/generic_containers.html#example" rel="noreferrer">example of how to use a Redis container</a>.</p>
  
  <p>At some point I understood that the test run correctly only when the development container was up and running. If it is down, the integration tests are falling because they can't reach Redis.</p>
  
  <p>So the integration test class looks like that:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(classes = SharkApplication.class,
      webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  @TestPropertySource(locations = "classpath:application-integrationtests.yml")
  @AutoConfigureMockMvc
  public class SharkIntegrationTest {
  static GenericContainer redis = new GenericContainer("redis:3.0.6")
          .withExposedPorts(6379);
  
  @BeforeClass
  public static void before(){
      redis.start();
  }
  
  @AfterClass
  public static void after(){
      redis.stop();
  }
  ...
  </code></pre>
  
  <p>When running the test, I can see this in the log:</p>
  
  <pre><code>14:36:24.372 [main] DEBUG  [redis:3.0.6] - Starting container: redis:3.0.6
  14:36:24.372 [main] DEBUG  [redis:3.0.6] - Trying to start container: 
     redis:3.0.6
  14:36:24.373 [main] DEBUG  [redis:3.0.6] - Trying to start container: 
      redis:3.0.6 (attempt 1/1)
  14:36:24.373 [main] DEBUG  [redis:3.0.6] - Starting container: redis:3.0.6
  14:36:24.373 [main] INFO  [redis:3.0.6] - Creating container for image: 
     redis:3.0.6
  ...
  14:36:25.282 [main] INFO  [redis:3.0.6] - Container redis:3.0.6 started
  </code></pre>
  
  <p>But then the app fails as it can't reach Redis:</p>
  
  <p><code>Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect</code></p>
  
  <p>At some point I tried to change the port on which the container should start. From 6379 to 16379 (changed both in the code and in the yml file), but then the test is entering an endless loop and prints to the screen:</p>
  
  <p><code>14:41:57.258 [ducttape-0] DEBUG org.testcontainers.containers.ExecInContainerPattern - /amazing_beaver: Running "exec" command: /bin/bash -c &lt;/dev/tcp/localhost/16379 &amp;&amp; echo</code></p>