Docker exec command with subprocess in Python program

I want to create a docker container through the subprocess function in the python program, and enter the container to execute the corresponding script to obtain the returned results. But I use. Subprocess.Popen function executes docker exec MySQL /bin/bash /home/test sh 'select * from userinfo;' Error 2002 (HY000): can't connect to local MySQL server through socket 'var / run / mysqld / mysqld sock'(2)。 Using the same command, I can run correctly at the terminal without reporting errors and get the desired results. Why?

Back to Top