Docker Community Forums

Share and learn in the Docker community.

Java JDBC connecting in docker can't connect to host database

i have maven container run spring boot and connect database with JDBC.

i want connect to host database

(host: Ubuntu/18.04.5 LTS (Bionic Beaver))

(database: mysql Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using EditLine wrapper)

this my connection string

this.conn = DriverManager.getConnection("jdbc:mysql://"+"user=xxxx&password=xxxx");

this my container IP

$ip route show
default via dev eth0 dev eth0 proto kernel scope link src

i can telnet and mysql login with IP or in maven container

$telnet 3306
Connected to
Escape character is '^]'.

telnet 3306
Connected to
Escape character is '^]'.

but i can’t connect via JDBC with IP or

Any help and tips are greatly appreciated!


Are you able to login to your database from within the Docker-container using mysql-command? It might by that the user is restricted to a hostname/ip-address.

Is your code working outside the Docker-container?
And are there any messages if you use docker logs <containername|containerid> ?


thank for your help

in my maven container, i can login to my database with mysql client command

$mysql -h -u root -p

my code work fine outside container and in my docker-container on Macbook
but in docker-container on Linux server it doesn’t work

this is log on my maven container

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
SQLState: 08S01
VendorError: 0