cant connect to postgres db - docker swarm

若如初见. 提交于 2019-12-13 03:53:26

问题


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:


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

port: 
- "5432"

should be:

port:
- "5432:5432"


来源:https://stackoverflow.com/questions/46424813/cant-connect-to-postgres-db-docker-swarm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!