I'm trying to connect to a database via SSH from my docker container. I'm getting an error

could not connect to server: Connection refused
    Is the server running on host "0.0.0.0" and accepting
    TCP/IP connections on port 5433?

I have a script to open the port and it works fine on my development, OSX Catalina.

bin/tunnel.sh

#!/usr/bin/expect -f
spawn ssh -fNg -L 5432:0.0.0.0:5432 myserver
expect "connecting"
send "yes"
expect "assword:"
send "mypassword\r"
interact

ENTRYPOINT

set -e

if [ -f tmp/pids/server.pid ]; then
  rm tmp/pids/server.pid
fi

service cron restart
./bin/tunnel.sh
foreman start -f Procfile.production web

database.yml

production: &production
  <<: *default
  # sslmode: "require"
  host: 0.0.0.0
  # pool: 100

EDIT

I wrongly assumed the DB is running inside the docker container, that's why my previous answer didn't work. The problem in your script above is that you specified 0.0.0.0:5432 as tunnel-endpoint.

This doesn't work, because the ssh clients needs a real ip / hostname it can connect to, localhost:5432 for example. If your Database is running on the same host you are ssh'ing to, -L 5432:localhost:5432 should work.