I have Spring app where I want to connect with MySQL db. I'm creating MySQL container using docker-compose.yml file:
version: '3.7'
services:
my-backend:
container_name: my-app
image: app
environment:
- _JAVA_OPTIONS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=dev
ports:
- "8010:8080"
build:
context: .
dockerfile: "Dockerfile"
depends_on:
- db
db:
container_name: mysql-app
image: mysql:5.7
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=my_user
- MYSQL_PASSWORD=my_pass
- MYSQL_DATABASE=my_db
ports:
- "3307:3306"
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
And there is application.yml file:
spring:
datasource:
url:jdbc:mysql://localhost:3307/my_db?serverTimezone=UTC&enabledTLSProtocols=TLSv1.2
username: root
password: root
When I want to connect to the db on port 3307 it is not possible because I've got error:
The driver has not received any packets from the server.
Connection refused
So my my guess falls on wrong port, but when I'm using phpMyAdmin this connects with db without problem.