Last times I often get error when using MySQL via Docker Compose:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
read unix @->/var/run/docker.sock: read: connection reset by peer
Exited with code 1
I have more containers but they work good, only problem with MySQL when I try to import database.
First time this error appeared 3-4 weeks ago, maybe more. Before everything worked fine, and now it works fine, but sometimes I get this error, and I need to rebuild 2-3 times and this error should disappear.
Thank you for reply, I added part of docker-compose.yml to my first message. But the problem is that php-fpm depends on mysql docker and it works fine. But I will try set sleep, maybe it will be fix my problem, but I dont think so, before run mysql container docker container with php run composer install and it takes some time, and then only mysql try to import database, I think it had much time for startup.
Hmm, the other thing that might be an issue - which I advised someone about recently on this board - is that you may be trying to connect to a MySQL database via a local socket when a TCP connection is required. I believe that TCP is necessary, since the server is not running locally.
Great. There is also a widely available wait-for-port command, you could try that as well (I forget what it is called). It basically keeps checking a specified port (e.g. 3306 for MySQL) until it is open. It may be a bit more reliable than a sleep.