无法连接到postgres db - docker swarm [英] cant connect to postgres db - docker swarm

查看:267
本文介绍了无法连接到postgres db - docker swarm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难通过IntelliJ连接到我的postgresql。
我正在使用这个docker-compose文件:

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

我把它放在命令中:

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

当我使用时:

docker ps

我明白了:

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

当我只想通过IntelliJ连接到db:

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

推荐答案

我发现问题:yml文件中的
错误:
而不是

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

port: 
- "5432"

应为:

port:
- "5432:5432"

这篇关于无法连接到postgres db - docker swarm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆