cant connect to postgres db - docker swarm

2019-08-28 04:23发布

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

1条回答
孤傲高冷的网名
2楼-- · 2019-08-28 04:49

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

port: 
- "5432"

should be:

port:
- "5432:5432"
查看更多
登录 后发表回答