title: Could not create connection to database server via Docker
body: <p>I have created a simple spring boot app to communicate with MYSQL via docker using the same network. Once I run <code>docker-compose up</code> command then following errors have occurred</p>
  <blockquote>
  <p>employee-jdbc-container | java.sql.SQLNonTransientConnectionException:
  Could not create connection to database server. Attempted reconnect 3
  times. Giving up.</p>
  <p>employee-jdbc-container | Caused by:
  com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval
  is not allowed</p>
  </blockquote>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: &quot;3&quot;   
  services:
    employee-mysql:
               image: employee-jdbc
               container_name: employee-jdbc-container
               ports:
               - &quot;9090:9090&quot;
               networks:
                 - employee-mysql2    
               depends_on:
                 - mysqldb
    mysqldb:
           image: mysql:8
           container_name: mysqldb
           ports:
           - &quot;3306:3306&quot;
           networks:
             - employee-mysql2
           environment:
             - MYSQL_USER=root
             - MYSQL_ROOT_PASSWORD=root
             - MYSQL_DATABASE=HR
  networks:                     
      employee-mysql2: 
  </code></pre>
  <p><strong>application.yml</strong></p>
  <pre><code>server:
    port: 9090
  
  spring:
    datasource:
      url: &quot;jdbc:mysql://mysqldb:3306/HR?createDatabaseIfNotExists=true&amp;autoReconnect=true&amp;useSSL=false&quot;
      username: root
      password: root
      platform: mysql
      initialization-mode: always
      driver-class-name: com.mysql.cj.jdbc.Driver
    jpa:
      database-platform: org.hibernate.dialect.MySQL8Dialect
  </code></pre>
  <p>I think the problem in the configuration file but have no idea what is wrong.</p>