Reputation: 4717
I'm having a problem connecting to a dockerized postgres
This is the container:
root@29de79c3cfa2:/# psql -U postgres -W
Password for user postgres:
psql (9.5.14)
Type "help" for help.
postgres=#
From Mac terminal:
psql --host localhos -p 5234 -U postgres -W
Password for user postgres:
psql: FATAL: role "postgres" does not exist
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
29de79c3cfa2 postgres:9.5 "docker-entrypoint.s…" 14 minutes ago Up 7 minutes 0.0.0.0:5234->5432/tcp postgres_1
It seems ports match (I do get the connection on 5234), but for some reason it does not recognize the role? How can this be possible if ssh'ing into the container allows me to connect to with that role?
Upvotes: 1
Views: 281
Reputation: 2372
It is working in my case. This is what I did
Run postgres docker image
[root@yellowdog ]# docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:9.5 5bf259c6d3f8be43aa3dc2aed4496a4992a8d1ba5b999507652fd13fcc109c25
Test the working of postgres from docker container from a different postgresql container
[root@yellowdog ]# docker run -it --rm --link postgres:postgres postgres psql -h postgres -U postgres
Password for user postgres:
psql (11.0 (Debian 11.0-1.pgdg90+2), server 9.5.14)
Type "help" for help.
postgres=# select 1;
1
(1 row)
postgres=# \q
Finally test the working from host machine
[root@yellowdog ]# psql -h localhost -U postgres
Password for user postgres:
psql (10.4, server 9.5.14)
Type "help" for help.
postgres=# select 1;
1
(1 row)
postgres=# \q
Upvotes: 1