简体   繁体   English

服务器重启后无法连接到 Docker 容器内的 MySQL

[英]Trouble connecting to MySQL within Docker container after server restart

I have a DigitalOcean droplet configured with Docker to host a MrSQL database.我有一个使用 Docker 配置的 DigitalOcean Droplet 来托管 MrSQL 数据库。 I am using an open source equivalent to Heroku to manage my containers called Caprover .我正在使用相当于 Heroku 的开源来管理我的名为Caprover 的容器。 This has worked excellent for me for months, but I realized that my MySQL database went down due to insufficient memory for InnoDB because my Docker instances were slowly taking up more memory over time.几个月来这对我来说效果很好,但我意识到我的 MySQL 数据库由于 InnoDB 的内存不足而宕机,因为我的 Docker 实例随着时间的推移慢慢地占用了更多的内存。 While debugging, I restarted my DigitalOcean droplet using sudo shutdown -r now .在调试时,我使用sudo shutdown -r now重新启动了我的 DigitalOcean droplet。 After restart (which normally fixes things), my db container logs displayed:重新启动后(通常可以解决问题),我的数据库容器日志显示:

[Note] mysqld: ready for connections.
Version: '5.7.28' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)

So at least on the container side it is ready for connections.因此,至少在容器方面,它已准备好进行连接。 I hopped back over to Sequel Pro to log back in and I get an immediate connection error:我跳回 Sequel Pro 重新登录,但立即出现连接错误:

Unable to connect to host MY_DIGITALOCEAN_IP, or the request timed out.

I have always used the following configuration to log in:我一直使用以下配置登录:

Host: MY_DIGITAL_OCEAN_IP
username: root
password: MY_PASSWORD
Port: 4444

In my container configuration, I have mapped the internal port 3306 to 4444 as seen on my dashboard here:在我的容器配置中,我已将内部端口 3306 映射到 4444,如此处的仪表板所示:

在此处输入图片说明

What are the next steps I need to take to try and debug what is causing this sudden loss of MySQL connection?我需要采取哪些后续步骤来尝试调试导致 MySQL 连接突然丢失的原因?

有趣的是,第二台服务器重启修复了问题......不知道为什么

I had a similar issue while running mysql in docker.我在 docker 中运行 mysql 时遇到了类似的问题。 Few things to take into consideration:需要考虑的几点:

1. Increase the memory allocation of docker. 
   You can do it easily using docker desktop dashboard.
2. Run the docker-compose with an admin access.
       For an example: sudo docker-compose -f mysql.docker-compose.yml up -d

Point 2 above will resolve inaccessible file issue.上面的第 2 点将解决无法访问的文件问题。

The above I have done it in my MacBook pro 11.5.1以上我已经在我的 MacBook pro 11.5.1 中完成了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM