Cant Connect to remote MySQL db from docker container on centos 8

I install docker in a centos 8 VPS. I have the MySQL server running on that VPS. While a container tries to connect the MySQL server, it says, “Can’t connect to MySQL server on ‘10.15.0.5’ (115)”

Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:25:41 2019
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:24:18 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.6
GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc:
Version: 1.0.0-rc8
GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
docker-init:
Version: 0.18.0
GitCommit: fec3683

Can anyone help me to resolve this error? I can confirm that the MySQL server configured correctly.

1 Like

Please post your “docker run …” commands
Are you trytion to reach you DB via net or socket ?

I used docker-compose to manage the docker container. And this is my docker-compose file. Mysql server not running on docker engine. I was trying to reach DB via net.

version: ‘3.8’
services:
redmine:
image: redmine:4.1.1-alpine
environment:
REDMINE_DB_MYSQL: 10.15.0.5
REDMINE_DB_PORT: 3306
REDMINE_DB_USERNAME: root
REDMINE_DB_PASSWORD: password
REDMINE_DB_DATABASE: database
ports:
- 8080:3000
volumes:
- ./data/:/usr/src/redmine/files

Thanks you

Can your reach (ping/telnet/curl) the Mysql Server from inside the container ? From the host ?

i can ping to the db host from the container.

This is the output when use mysql client in another container

mysql -u root -h 10.15.0.5 -P 3306 -ppassword

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘10.15.0.5’ (113)

This is my telnet output

telnet 10.15.0.5 3306

Trying 10.15.0.5…
telnet: Unable to connect to remote host: No route to host