Trouble connecting to Docker Postgres DB from host system #3190
-
I'm having trouble connecting to the Postgres server from the host system. I want to look under the hood at the raw database data.
But I can't get the command to connect to it right. I've tried:
I have the feeling I'm making a rookie Docker error - or does the config need changing to allow this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
👋 @phlbnks In the default setup PostgreSQL runs in an isolated network namespace so it's not accessible from host. However, it doesn't stop you from accessing it and there are several ways to do it:
$ cd hosting
$ docker compose exec plausible_db ash
/ # psql -U postgres
psql (14.7)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+----------+----------+------------+------------+-----------------------
plausible_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=# \c plausible_db
You are now connected to database "plausible_db" as user "postgres".
plausible_db=# |
Beta Was this translation helpful? Give feedback.
And connecting to it from the host
$ psql -h localhost -p 5432 -U postgres