无法从Docker容器连接到远程MySQL数据库

时间:2020-05-19 18:49:35

标签: docker docker-compose docker-swarm centos8

我在centos 8 VPS中安装了docker。我的VPS上运行的是MySQL服务器。我的容器尝试连接MySQL服务器时,发生了错误。

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

这是我的docker版本

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

当我安装最新的docker-engine时,发生了相同的错误。

1 个答案:

答案 0 :(得分:0)

允许在防火墙上伪装

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

请参阅this解释。