title: From Springboot app connect to mysql container
body: <p><em>Hello guys !</em></p>
  
  <p>It's my first so I will try to make the best that I can.</p>
  
  <p>I want to create an app which is running with Springboot framework and I would like to connect it to a docker container which embeds MySQL (but the spring boot app is not running on docker)</p>
  
  <p>So I have followed this  <a href="https://stackoverflow.com/questions/32360687/connect-to-docker-mysql-container-from-localhost">post</a></p>
  
  <p>I have made my docker-compose:</p>
  
  <pre><code>  db:
       image: mysql
    ports:
       - '3306:3306'
    environment:
       - MYSQL_ROOT_PASSWORD=secret
       - MYSQL_DATABASE=users
    volumes:
       - ../data:/var/lib/mysql
  </code></pre>
  
  <p>and I run it with this command :</p>
  
  <pre><code>docker-compose run --service-ports db
  </code></pre>
  
  <p>All is fine, so now I change my application.properties on spring boot :</p>
  
  <pre><code>   ## Server Properties 
     server.port= 5000
  
     ## Spring DATASOURCE (DataSourceAutoConfiguration &amp; DataSourceProperties)
     spring.datasource.url= jdbc:mysql://127.0.0.1:3306/users?useSSL=false&amp;serverTimezone=UTC&amp;useLegacyDatetimeCode=false
     spring.datasource.username= root
     spring.datasource.password= secret
  
     ## Hibernate Properties
  
     #The SQL dialect makes Hibernate generate better SQL for the chosen database
  
     spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
     spring.jpa.hibernate.ddl-auto = update
  
     ## Hibernate Logging
     logging.level.org.hibernate.SQL= DEBUG
  
     ## Jackson Properties
     spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS= false
     spring.jackson.time-zone= UTC
  </code></pre>
  
  <p>But When I run my app, I have this error :( :</p>
  
  <blockquote>
    <p>Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure</p>
  </blockquote>
  
  <p>I'm on MacOS...</p>
  
  <p>I tried to follow callicoder's course ...</p>
  
  <p><a href="https://www.callicoder.com/spring-boot-spring-security-jwt-mysql-react-app-part-1/" rel="nofollow noreferrer">https://www.callicoder.com/spring-boot-spring-security-jwt-mysql-react-app-part-1/</a></p>
  
  <p>Thanks for your help :)</p>