title: docker-compose mysql Connection refused
body: <p>my development environment</p>
  <ul>
  <li>Spring Boot 2.x, Gradle, Mybatis</li>
  </ul>
  <p>Simply build through Docker-compose and create a project for API testing.
  Why do I keep getting connection refused?</p>
  <p>If you type the command 'docker-compose up', it runs without any problem.</p>
  <p>I checked the network and it is connected.</p>
  <p>I usually use 'docker exec A ping B' to check.</p>
  <p>I don't know why an error occurs when A is a DB container.
  I'll attach the code just in case.</p>
  <pre><code># application.properties
  spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  spring.datasource.url=jdbc:mysql://test-db:3306/exdocker?serverTimezone=Asia/Seoul
  spring.datasource.username=dockerex
  spring.datasource.password=12341234
  
  </code></pre>
  <pre><code># docker-compose.yml
  version: &quot;3&quot;
  services:
    test-db:
      container_name: test-db
      image: mysql:8.0
      environment:
        MYSQL_DATABASE: &quot;exdocker&quot;
        MYSQL_ROOT_PASSWORD: &quot;root&quot;
        MYSQL_PASSWORD: &quot;12341234&quot;
        MYSQL_USER: &quot;dockerex&quot;
      restart: always
      networks:
        - exdocker-network
      ports:
      - 3307:3306
  
    test-app:
      links:
        - test-db
      build:
        context: .
        dockerfile: Dockerfile
      ports:
      - 8081:8080
      restart: always
      networks:
        - exdocker-network
      depends_on:
        - test-db
  
  networks:
    exdocker-network:
      ipam:
        driver: default
        config:
          - subnet: 172.202.0.1/16
  </code></pre>