PSQL Shell 和我的 jdbc-url 都无法在应用程序启动时找到我的 Docker 容器数据库

PSQL Shell nor my jdbc-url can find my Docker container databases on application boot up

我正在尝试学习 SpringBoot 教程 here

最后一幕是使用 .yml 文件将我的逻辑代码桥接到容器化数据库。启动时,应用程序未在

处找到我的容器化数据库

jdbc-url: jdbc:postgresql://localhost:5432/demodb

我收到这个错误

致命:数据库“demodb”不存在

使用 psql shell 创建数据库“demodb”是避免此错误的唯一方法,但是,

我希望能够使用容器的数据库,并且我相信 psql shell 可以看到在我的容器中创建的内容。 The screenshot here proves otherwise (Left is the shell). (Right is the container)

所有登录(对于容器和 shell)都是相同的,但在命令提示符下输入 psql -U postgres 会导致我的本地主机 psql。

当我使用 \conninfo 时,我的 shell 的数据库在端口“5432”连接到“localhost”(地址“::1”),而容器数据库通过“/var/run/postgresql" 在端口 "5432".

将我的 jdbc 更改为 jdbc-url: jdbc:postgresql://var/run/postgresql:5432/demodb 也没有用。

是不是因为我电脑上有两个不同的psql?

作为我自己问题的答案,那些想要 jdbc url 连接到 docker 容器数据库的人必须确保停止任何 Postgresql 12 服务.

最初,我的连接在我的容器 IP 上被拒绝,但我可以通过终端连接。我的 postgres dbms 也在本地主机中。