title: docker-compse.yml spring boot mysql configuration
body: <p>I have been trying to configure docker for my spring boot application with MySQL. But, I keep getting <strong>communications link failure</strong> error after running </p>
  
  <blockquote>
    <p>docker compose up</p>
  </blockquote>
  
  <p>Here's a snapshot of the error</p>
  
  <pre><code>spring-batch_1  | 2019-11-14 06:23:43.713  INFO 1 --- [           main] 
  com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
  spring-batch_1  | 2019-11-14 06:23:43.918 ERROR 1 --- [           main] 
  com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool 
  initialization.
  spring-batch_1  | 
  spring-batch_1  | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link 
  failure
  spring-batch_1  | 
  spring-batch_1  | The last packet sent successfully to the server was 0 milliseconds ago. The 
  driver has not received any packets from the server.
  spring-batch_1  |       at 
  com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[ . 
  mysql-connector-java-8.0.18.jar!/:8.0.18]
  spring-batch_1  |  at
  com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException
  (SQLExceptionsMapping.java:64 ) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
  spring-batch_1  |       at 
  com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java- 
  8.0.18.jar!/:8.0.18]
  spring-batch_1  |       at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456) ~ 
  [mysql-connector-java-8.0.18.jar!/:8.0.18]
  spring-batch_1  |       at 
  com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java- 
  8.0.18.jar!/:8.0.18]
  spring-batch_1  |       at 
  com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql- 
  connector-java-8.0.18.jar!/:8.0.18]
  spring-batch_1  |       at 
  com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP- 
  3.4.1.jar!/:na]
  spring-batch_1  |       at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353) ~ 
  [HikariCP-3.4.1.jar!/:na]
  spring-batch_1  |       at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) ~ 
  [HikariCP-3.4.1.jar!/:na]
  spring-batch_1  |       at 
  com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473) ~[HikariCP- 
  3.4.1.jar!/:na]
  spring-batch_1  |       at 
  com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562) ~[HikariCP- 
  3.4.1.jar!/:na]
  spring-batch_1  |       at com.zaxxer.hikari.pool.HikariPool.&lt;init&gt;(HikariPool.java:115) ~ . 
  [HikariCP-3.4.1.jar!/:na]
  spring-batch_1  |       at 
  com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP- 
  3.4.1.jar!/:na]
  spring-batch_1  |       at 
  com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(&lt;generated&gt;) ~ . 
  [HikariCP-3.4.1.jar!/:na]
  spring-batch_1  |       at 
  org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core- 
  5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
  spring-batch_1  |       at 
  org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint
  (CglibAopProxy.java:769) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
  spring-batch_1  |       at 
  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
  (ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
  spring-batch_1  |       at 
  org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed
  (CglibAopProxy.java:747) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
  spring-batch_1  |       at 
  org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed
  (DelegatingIntroductionInterceptor.java:136) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
  </code></pre>
  
  <p>Here's my <strong>docker-compose.yml</strong> file</p>
  
  <pre><code>version: "3.3"
  services:
    mysql:
      restart: always
      image: mysql:latest
      ports:
        - 6033:3306
      expose:
        - 6033
      volumes:
        - db_data:/var/lib/mysql
      environment:
        - MYSQL_ROOT_PASSWORD=root@123
        - MYSQL_DATABASE=micro_services
        - MYSQL_USER=root
        - MYSQL_PASSWORD=root@123
    spring-batch:
      restart: always
      image: ioesandeep/product-service:0.0.1-SNAPSHOT
      ports:
        - "8082:8082"
      environment:
         SPRING_DATASOURCE_URL: jdbc:mysql://127.0.0.1:6033/micro_services
         SPRING_DATASOURCE_USERNAME: root
         SPRING_DATASOURCE_PASSWORD: root@123
         SPRING_JPA_DATABASE: mysql
      depends_on:
        - mysql
  volumes:
    db_data: {}
  </code></pre>
  
  <p>and here's my <code>dockerfile</code> which is used to build my <strong>spring-batch image</strong></p>
  
  <pre><code>FROM openjdk:11-jdk
  VOLUME /tmp
  ARG JAR_FILE
  ADD ${JAR_FILE} product.jar
  ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/product.jar"]
  </code></pre>
  
  <p>I am using <strong>dockerfile-maven-plugin</strong> from <strong>com.spotify</strong> to build the image.
  Here's my <strong>application.properties</strong> file for the spring boot and hibernate</p>
  
  <pre><code>spring.application.name=product
  server.port=8082
  spring.jpa.hibernate.ddl-auto=create-drop
  spring.datasource.url=jdbc:mysql://127.0.0.1:6033/micro_services
  spring.datasource.username=root
  spring.datasource.password=root@123
  spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  spring.jpa.database=mysql
  spring.batch.initialize-schema=always
  spring.batch.job.enabled=false
  </code></pre>
  
  <p><code>Docker version 18.09.2, build 6247962</code></p>
  
  <p><code>mysql  Ver 8.0.18 for macos10.14 on x86_64 (MySQL Community Server - GPL)</code></p>
  
  <p><strong>Images</strong></p>
  
  <p><code>mysql                          latest                    c8ee894bd2bd        4 weeks ago</code></p>
  
  <p><code>openjdk                        11-jdk                    a7e47afa852b        3 weeks ago</code></p>
  
  <p>I have tried a lot many configurations for the docker-compose file but every time I get the same error. I am not sure what am I missing in the configuration. I have been trying to get this up for over 2 days now. I would really appreciate a quick help.
  Thanks</p>