title: JDBC Communications link failure with mysql docker container
body: <p>When my java spring application tries to connect to the database I get the following:</p>
  
  <pre><code>Caused by: 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.
  </code></pre>
  
  <p>The connection url in the spring application is as follows:</p>
  
  <p>jdbc:mysql://mysqldbserver:3306/supersede_orchestrator_spring?useSSL=false&amp;autoReconnect=true&amp;failOverReadOnly=false&amp;maxReconnects=10</p>
  
  <p>where mysqldbserver is the service name from the docker-compose config:</p>
  
  <pre><code>version : '3'
  services:
    springappserver:
      build:
        context: .
        dockerfile: web.dockerfile
      ports:
        - "8081:8080"
      networks:
        - mt-network
      volumes:
        - .:/vol/development
      depends_on:
        - mysqldbserver
    mysqldbserver:
      build:
        context: .
        dockerfile: db.dockerfile
      ports:
        - "13306:3306"
      networks:
        - mt-network
      environment:
        MYSQL_DATABASE: supersede_orchestrator_spring
        MYSQL_USER: supersede_orch
        MYSQL_PASSWORD: ****
        MYSQL_ROOT_PASSWORD: ****
      container_name: orchestrator_mysqldbserver
  networks:
    mt-network:
      driver: bridge
  </code></pre>
  
  <p>In the mysql docker container I already adjusted the bind-address to 0.0.0.0. The privileges of the supersede_orch user are set to %. 
  When I connect to the springappserver docker container, I can reach the database via telnet mysqldbserver 3306 and I can also connect to the database on the command line from the spring docker container: mysql -h mysqldbserver -u supersede_orch -p.
  Though the java spring application fails to connect to the DB running on the other docker container. </p>
  
  <p>The web.dockerfile looks as follows:</p>
  
  <pre><code>FROM java:8-jre
  
  VOLUME /tmp
  ADD build/libs/feedback_orchestrator-2.0.0.jar app.jar
  
  RUN apt-get update
  RUN apt-get install mysql-client -y
  RUN apt-get install libmysql-java -y
  
  RUN bash -c 'touch /app.jar'
  
  ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom -Djava.net.preferIPv4Stack=true","-jar","/app.jar"]
  </code></pre>
  
  <p>So, I tried to make sure that java uses IP4 to resolve mysqldbserver (I also used the corresponding IP address for mysqldbserver which also failed).</p>
  
  <p>Finally docker images -a:</p>
  
  <pre><code>42db4e656e6e        orchestrator_springappserver   "java '-Djava.secu..."   16 minutes ago      Up 16 minutes             0.0.0.0:8081-&gt;8080/tcp    orchestrator_springappserver_1
  e2b0b5cc15ac        orchestrator_mysqldbserver     "docker-entrypoint..."   2 hours ago         Up About an hour          0.0.0.0:13306-&gt;3306/tcp   orchestrator_mysqldbserver
  </code></pre>
  
  <p>Do you have any idea what the problem could be? Thank you!</p>