title: How to connect my Java application to Cassandra running through docker?
body: <p>I have the following java code:</p>
  
  <pre><code>String serverIP = "127.0.0.1";  
  String keyspace = "testkeyspace"; 
  Cluster cluster = Cluster.builder().addContactPoints(serverIP).build();  
  Session session = cluster.connect(keyspace);
  </code></pre>
  
  <p>which i am trying to use to check my connection to Cassandra.</p>
  
  <p>I have Cassandra locally installed in my own machine, and connecting there is successful.
  My maven project is using the following</p>
  
  <blockquote>
    <p>spring-data-cassandra
    2.0.6.RELEASE</p>
  </blockquote>
  
  <p>However, when i am trying to connect my java application to Cassandra run by docker (with my local cassandra stopped) i encounter the following error:</p>
  
  <blockquote>
    <p>All host(s) tried for query failed (tried: /127.0.0.1:9042
    (com.datastax.driver.core.exceptions.TransportException:
    [/127.0.0.1:9042] Cannot connect))</p>
  </blockquote>
  
  <p>I do not know if my IP is wrong, but on my docker CQLSH the following message is written whenever i open my CQLSH:</p>
  
  <blockquote>
    <p>Connected to Test Cluster at 127.0.0.1:9042. 
    [cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help.</p>
  </blockquote>
  
  <p>Please help, i must have missed something here. Thank you!</p>