title: Connect Spring with MySql in Docker container
body: <p>When i follow this tutorial: <a href="https://spring.io/guides/gs/accessing-data-mysql/#initial" rel="nofollow noreferrer">https://spring.io/guides/gs/accessing-data-mysql/#initial</a> and spin up some new docker containers:</p>
  
  <pre><code>version: '2'
  
  services:
      db:
        image: mysql
        environment:
                  - MYSQL_DATABASE=test
                  - MYSQL_USER=test
                  - MYSQL_PASSWORD=secret
                  - MYSQL_ROOT_PASSWORD=root
        volumes:
              - ./db:/var/lib/mysql
        ports:
              - "3306:3306"
      phpmyadmin:
       image: phpmyadmin/phpmyadmin
       environment:
              PMA_ARBITRARY: 1
              MYSQL_USER: test
              MYSQL_PASSWORD: secret
              MYSQL_ROOT_PASSWORD: root
       ports:
              - "80:80"
       links:
              # for mysql container
              - "db:db"
  volumes:
      db:
          driver: "local"
  </code></pre>
  
  <p>Im not able to connect with the MySql database, when i run the example application in Spring i get the error:</p>
  
  <pre><code>Unable to create initial connections of pool.
  
  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>My application properties:</p>
  
  <pre><code>spring.jpa.hibernate.ddl-auto=create
  spring.datasource.url=jdbc:mysql://db:3306/test
  spring.datasource.username=springuser
  spring.datasource.password=ThePassword
  </code></pre>
  
  <p>What goes wrong? I tried also different combinations like localhost. I can reach phpmyadmin in my browser.</p>