-->

Tuesday, November 29, 2022

[Solved] sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '127.0.0.1'

 

Issue:- 

When  launching a container from the application image, application needs to connect to the mysql database running on the host machine. But when you try to connect using the localhost or 127.0.0.1 you get the following error.

Error:- 

Effect:-

Application container went down because application was not able to connect to the mysql database.

Resolution:-
Since the mysql database is running on the host machine so it makes sense that we use the --network=host which will disable the docker networking and use the host based networking and than your docker container will be able to connect to the host database since both are in the same network.

docker run -d --network=host project_app1:latest