Docker mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I have created a MySQL container and hope to execute shell script in the container and execute SQL statement to get the return result, which is a part of my Django project. Using docker library to create container and execute script in Python program, I get ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)。 But when I execute the same command in the shell to create the container and execute the script, there will be no error. I want to know why. Who can help me, thank you! enter image description here enter image description here

Back to Top