That is a good best practice indeed. Use the database with docker just for small sized projects. For larger projects use a managed RDS from Amazon RDS or Digital Ocean managed database.
The error above shows that a wrong address is used to connect, see: