Accessing Postgres database inside Dokku container from outside
To connect with a pgadmin you can get all the necessary information from the DATABASE_URL.
➜ ~ dokku postgres:info your-database-db
DSN: postgres://postgres:bf8f1cb443c35cd1ae0a58617ef348cd@dokku-postgres-your-database-db:5432/your_database_db
Because dokku have the same foundation as Heroku you can extract the information to connect with pg database. The important consideration is that dokku generate a random port for exposure your database. You can get a random port or set any that you want.
[database type]://[username]:[password]@[host]:[port]/[database name]
Exposing the database and getting the real port:
➜ ~ dokku postgres:expose your-database-db
! Service is already started
-----> Service your-database-db exposed on port(s) 17825
Now in your pg admin you will add the next information and hopefully connect without issues.
username: postgres
password: bf8f1cb443c35cd1ae0a58617ef348cd
hostname: Your-Dokku-Host-URL (Ex. example.com or IP of your dokku server)
port: 17825
Also, if you are running dokku in AWS EC2, for example, you need to allow access to this port on the instance, adding a Custom TCP Rule in the Inbound section of the Security Group this instance is associated with.