Accessing Postgres database inside Dokku container from outside
Asked Answered
B

2

16

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.

Beaty answered 18/1, 2016 at 9:33 Comment(0)
C
50

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.

Ciccia answered 15/2, 2016 at 18:44 Comment(2)
In testing this command, I noticed you may need to specify the port you'd like to expose (running dokku version 0.19.6): dokku postgres:expose your-database-db PORTFortnightly
In addtion to specifying the port, you can also give the IP to use: 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
S
0

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 internet
  • Internal 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.

Sylvester answered 15/6, 2023 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.