title: Tomcat container and Mysql container join using docker-compose
body: <p>I am new to Docker. And I checked this answer <a href="https://stackoverflow.com/questions/35510964/unable-to-connect-mysql-container-to-tomcat-container-in-docker">Unable to Connect MySQL container to Tomcat Container in docker</a>
  But It does not work for me. That's why I Post this problem.
  My docker-compose is bellow.</p>
  
  <pre><code>version: '3'
  services:
      web:
          build: .
          ports:
           - "4000:8080"
          links:
           - db
  
      db:
          image: mysql:latest
          environment:
              MYSQL_ROOT_PASSWORD: root
              MYSQL_DATABASE: custom
              MYSQL_USER: root
              MYSQL_PASSWORD: root
          volumes:
           - ./mysql-data:/var/lib/mysql 
  </code></pre>
  
  <p>Through this I need to make a connection. I am using jsp file to make connection and get the data. my jsp file is bellow.</p>
  
  <pre><code> &lt;%@ page import="pageNumber.*,java.util.*, java.io.*, java.sql.*"%&gt;
      &lt;!DOCTYPE html&gt;
      &lt;body&gt;
          &lt;% 
          try {
            Connection con;
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://db:3306/custom?useSSL=false", "root", "root");
            if(con!=null){
                out.println ("database successfully opened.");
                out.println(con);
            }
  
          }
          catch(SQLException e) {
            out.println("SQLException caught: " +e.getMessage());
          }
        %&gt;
      &lt;/body&gt;
  </code></pre>
  
  <p>I read <a href="https://stackoverflow.com/questions/35510964/unable-to-connect-mysql-container-to-tomcat-container-in-docker">Unable to Connect MySQL container to Tomcat Container in docker</a> problem carefully and make the changes. But still I am getting this error.</p>
  
  <blockquote>
    <p>SQLException caught: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.</p>
  </blockquote>
  
  <p>Please can anyone help me to solve this problem.  Thank you for your time</p>