Tuesday, November 29, 2022

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



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 you get the following error.



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

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