title: Can't connect a spring-boot 2 service to mysql in a different container
body: <p>I have a spring-boot 2.16 service that connects to a my-sql data base. It works as expected as far as all the components are on the same host. I tried to improve the solution and to have a docker container running the sprin-boot service with Tomcat embedded and another docker container running the my-sql server.
  The same code doesn't work any more. here is the exception:</p>
  
  <pre><code> 2019-06-28 12:23:48 ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
   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)
  at  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
  at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:988)
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:341)
  ....
  Caused by: java.net.ConnectException: Connection refused (Connection refused)
  at java.net.PlainSocketImpl.socketConnect(Native Method)
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  at java.net.Socket.connect(Socket.java:589)
  at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:300)
  ... 66 common frames omitted
  </code></pre>
  
  <p>So, it's like the my-sql server IP address is not found or the server is not running, etc.
  Here is the docker-compse.yml file:</p>
  
  <pre><code>version: "2"
  services:
    rdf-data:
      container_name: rdf-data
      image: mysql:latest
      environment:
        MYSQL_DATABASE: test
        MYSQL_USER: nicolas
        MYSQL_PASSWORD: mysql
        MYSQL_ROOT_PASSWORD: mysql
      ports:
        - 3306:3306
        - 33060:33060
      hostname: rdf-data
      networks:
        net1:
          ipv4_address: 192.19.0.4
    rdf-core:
      image: openjdk:8-jdk-alpine
      depends_on:
        - rdf-data
      container_name: rdf-core
      links:
        - rdf-data:rdf-data
      volumes:
        - ../docker:/usr/local/share/rdf
      ports:
        - "8080:8080"
      entrypoint: /usr/local/share/rdf/run.sh
      hostname: rdf-core
      environment:
        PROFILE: "default"
        SERVER_PORT: "8080"
    networks:
      net1:
        ipv4_address: 192.19.0.8
  networks:
    net1:
      driver: bridge
      driver_opts:
        com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
      config:
        - subnet: 192.19.0.0/24
          gateway: 192.19.0.1
  </code></pre>
  
  <p>Here there are two containers: rfd-core having the IP address of 192.19.0.8 and rdf-data having the IP address 192.19.0.4. Each container is able to ping the other. The hst machine is able to ping each container. From the host machine I'm able to correctly connect to the my-sql server running on rfd-data using the my-sql command line client.
  However, my service connection shown here below doesn't work:</p>
  
  <pre><code>database=mysql
  spring.datasource.url=jdbc:mysql://192.19.0.4/test?useSSL=false
  spring.datasource.username=root
  spring.datasource.password=mysql
  spring.datasource.driver-class=com.mysql.cj.jdbc.MysqlXADataSource
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.datasource.hikari.connectionTimeout=30000
  spring.datasource.hikari.idleTimeout=600000
  spring.datasource.hikari.maxLifetime=1800000
  ...
  </code></pre>
  
  <p>Is there anything I'm missing?</p>