0

I am new to Docker. And I checked this answer Unable to Connect MySQL container to Tomcat Container in docker But It does not work for me. That's why I Post this problem. My docker-compose is bellow.

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 

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.

 <%@ page import="pageNumber.*,java.util.*, java.io.*, java.sql.*"%>
    <!DOCTYPE html>
    <body>
        <% 
        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());
        }
      %>
    </body>

I read Unable to Connect MySQL container to Tomcat Container in docker problem carefully and make the changes. But still I am getting this error.

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.

Please can anyone help me to solve this problem. Thank you for your time

dhananjana
  • 53
  • 1
  • 12

1 Answers1

0

https://docs.docker.com/compose/compose-file/#build according to their documentation. I think we cannot give

build .

in docker-compose.yml need to give directory after the build command. In this case I made that incorrect way.

correct way

build ./dir

dhananjana
  • 53
  • 1
  • 12