title: Communications link failure , Spring Boot + MySql +Docker + Hibernate
body: <p>I'm working with spring boot, hibernate &amp; MySql. While running the application it is running well as per expectation . But while making the docker-compose file and running the app docker image with mysql docker image it gives this error.</p>
  <blockquote>
  <p><strong>Error</strong>
  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  java.net.ConnectException: Connection refused.</p>
  </blockquote>
  <pre><code>private Connection createConnection() throws SQLException 
  {
          DriverManager.registerDriver(new com.mysql.jdbc.Driver());
          String mysqlUrl = &quot;jdbc:mysql://localhost/database?autoReconnect=true&amp;useSSL=false&quot;;
          Connection connection = DriverManager.getConnection(mysqlUrl, &quot;root&quot;, &quot;root&quot;);
          return connection;
  }
  </code></pre>
  <blockquote>
  <p><strong>Application.properties</strong></p>
  </blockquote>
  <blockquote>
  <p>spring.datasource.url=jdbc:mysql://localhost/database?autoReconnect=true&amp;useSSL=false
  spring.datasource.username=root</p>
  </blockquote>
  <blockquote>
  <p>spring.datasource.password=root</p>
  </blockquote>
  <p>Please guide me how to tackle this.</p>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: '3'
  
  services:
    docker-mysql:
      image: mysql:5.7
      environment:
        - MYSQL_ROOT_PASSWORD=root
        - MYSQL_DATABASE=database
        - MYSQL_USER=root
        - MYSQL_PASSWORD=root
      ports:
        - 3307:3306
  
    app:
      image: app:latest
      ports:
         - 8091:8091
      depends_on:
         - docker-mysql
  </code></pre>