I'm having a hard time finding a way to access Postgres database inside Dokku's contaner (based on docker) from outside of the machine using pgAdmin. Is there a way to do that? Do I need to use a different client? I'm exposing database using dokku postgres:expose
command.
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.
dokku postgres:expose your-database-db 127.0.0.1:1234
to expose on localhost for example (useless here given the question, but it’s to give an example). This is useful to expose only on private IPs. –
Selfpity It's also possible using ssh tunnel.
dokku postgres:list
for all postgres instances
dokku postgres:info DBNAME
checks exposed ports (if it has) and credentials
- Use
DNS
for credentials, as mentioned in previous answer Exposed ports
- check whether app looks to the internetInternal IP
- host ip, that can be used over ssh
In your postgres client choose an option with ssh tunnel or forward port using putty or etc.
© 2022 - 2024 — McMap. All rights reserved.
dokku postgres:expose your-database-db PORT
– Fortnightly