0

I have difficulties to connect to my postgresql via IntelliJ. I am using this docker-compose file:

version: '3'
services:
 db:
  image: postgres
  environment:
   POSTGRES_DB: postgres
   POSTGRES_USER: postgres_user
   POSTGRES_PASSWORD: postgres_password
   PG_DATA: /var/lib/postgresql/data/pgdatai
  expose:
   - "5432"
  ports:
   - "5432"
  volumes:
   - /var/lib/postresql/db/
  deploy:
   placement:
    constraints:
     - node.hostname == vmAPT1

I put this inside by command:

docker stack deploy --compose-file docker-compose.yml vmAPT1

when I use:

docker ps

I see:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
31d1337a142c        postgres:latest     "docker-entrypoint..."   30 minutes ago      Up 30 minutes       5432/tcp            vmAPI1_db.1

And when I am trying simply to connect to db by IntelliJ:

jdbc:postgresql://192.168.200.140:5432/postgres

I am recieving that connection failed. How to handle that?? I thought that the port is open for connections

xross
  • 515
  • 3
  • 8
  • 23
  • Can you provide the error logs from the server for PostgreSQL? – AK47 Sep 26 '17 at 11:09
  • It should look similar to: `2017-09-09 18:10:17 UTC [2740-2] postgres_user@postgres FATAL: Peer authentication failed for user "postgres_user"` – AK47 Sep 26 '17 at 11:11
  • @AK47 I can have only logs from docker service logs id_of_service. And they are very poor. I dont see any more possibilities to gain logs, which you are talking about. – xross Sep 26 '17 at 11:21
  • what is the output `docker service ls` – Tarun Lalwani Sep 26 '17 at 11:40
  • @xross Your pgdata directory is wrong, it should be `PG_DATA: /var/lib/postgresql/data` or have you initialised your database cluster in `/pgdatai`? – AK47 Sep 26 '17 at 11:41
  • Thx, already found the problem :/ – xross Sep 26 '17 at 11:45

1 Answers1

1

I found the problem: mistake in yml file: instead of

port: 
- "5432"

should be:

port:
- "5432:5432"
xross
  • 515
  • 3
  • 8
  • 23