Search code examples
dockerdocker-composedocker-swarmcentos8

Cant Connect to remote MySQL db from docker container


I install docker in a centos 8 VPS. I have the MySQL server running on my VPS. While my container tries to connect the MySQL server, the error has occurred.

Can't connect to MySQL server on '10.15.0.5' (115)

This my docker version

docker version

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

When I installed the latest docker-engine same error occurred.


Solution

  • Allow masquerading on firewalld

    firewall-cmd --zone=public --add-masquerade --permanent
    firewall-cmd --reload
    

    Refer this explanation.