Troubles with docker+postgre

Hello everyone. There was such a problem in postgre and docker. The bottom line: there is a Python script on the server-telegram bot. It works with postgre. If you run it on the server, everything is fine. If in postgre, what is in docker-problems begin. I did port forwarding using dockerfile to the host-it works clumsily. The python script works via psycopg2 import-connects to the database, authorizes. But there are always some mistakes. The script is written (sort of) exactly. I went through dockerfile, docker-compose.yml, and still - nonsense. Task: to work smoothly, without errors. If someone understands, please tell me.

Your post is to ambiguous (at least for me) to get an idea of the root cause.

Please add a code example and share the exact error messages from the log. Make sure you format the shared code example and error messages according How to format your forum posts - do not share them as screenshot. Thank you!