The connection refused error is likely happening because the database container isn't ready when the backend service tries to connect. I can tell you about Python, add a connection retry mechanism in your Python code.
Let me know if you can figure this out; otherwise, I'm happy to help you. I can provide some examples.