title: Can't conect SpringBoot to MySql using Docker compose
body: <p>I have created a docker compose file, to connect MySql to a SpringBoot app. But i get this error:</p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_242]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_242]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_242]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_242]
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:342) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2221) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2016) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:776) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_242]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_242]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_242]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_242]
  </code></pre>
  
  <p>My Dockerfile, Ihave created a .jar file using Maven install:</p>
  
  <pre><code>FROM openjdk:8
  EXPOSE 8083
  ADD target/ProjectCrud.jar ProjectCrud.jar
  ENTRYPOINT ["java", "-jar", "ProjectCrud.jar"]
  </code></pre>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: '3'
      services:
      docker-mysql:
          restart: always
          container_name: docker-mysql
          image: mysql
          environment:
              MYSQL_DATABASE: pfa
              MYSQL_ROOT_PASSWORD: aze123qsd
              MYSQL_USER: root
              MYSQL_ROOT_HOST: '%'
          volumes:
              - ./sql:/docker-entrypoint-initdb.d
          networks:
              - spring-db
  
          ports:
              - "3306:3306"
          healthcheck:
              test: "/usr/bin/mysql --user=root --password=root--execute \"SHOW DATABASES;\""
          interval: 2s
          timeout: 20s
          retries: 10
  
  
      sign-up-app:
          build: ./
          expose:
              - "10222"
          ports:
              - 10222:10222
          environment:
              WAIT_HOSTS: mysql:3306
          depends_on:
              - docker-mysql
          networks:
              - spring-db
    networks:
        spring-db:
  </code></pre>
  
  <p>My application.properties:</p>
  
  <pre><code>spring.datasource.username=root
  spring.datasource.password=aze123qsd
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.jpa.hibernate.ddl-auto=update
  spring.datasource.url=jdbc:mysql://docker-mysql:3306/pfa? 
  useUnicode=true&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC
  server.port=8089
  </code></pre>
  
  <p>I tried to run my spring boot app in my local machine using docker default ip while runnig only MySql container in this docker-compose.yml file, and it worked perfectly. But when I try to docker compose the file. i get this error.</p>