英文:
PSQL Shell nor my jdbc-url can find my Docker container databases on application boot up
问题
我正试图跟随一个SpringBoot教程,链接在这里,最后一步是使用一个.yml文件将我的逻辑代码与容器化的数据库连接起来。在启动时,应用程序无法在以下位置找到我的容器化数据库:
jdbc-url: jdbc:postgresql://localhost:5432/demodb
我得到了这个错误:
FATAL: database "demodb" does not exist
为了避免这个错误,我唯一的方法是使用psql shell创建数据库"demodb",但是我希能够使用容器内的数据库,我认为psql shell应该能够看到在我的容器中创建的内容。
这里的屏幕截图证明了不同(左边是shell),(右边是容器)
所有登录(容器和shell)都是相同的,但是在命令提示符中输入psql -U postgres会进入我的本地主机psql。
当我使用\conninfo时,我的shell数据库连接到地址为"localhost"(地址"::1")的端口"5432",而容器数据库通过位于"/var/run/postgresql"的套接字连接到端口"5432"。
将我的jdbc更改为jdbc-url: jdbc:postgresql://var/run/postgresql:5432/demodb也不起作用。
这是因为我在计算机上有两个不同的psql吗?
英文:
I am attempting to follow along a SpringBoot tutorial
here
and the final act is using a .yml file to bridge my logic code to a containerized database. On start up, the application does not find my containerized database at
jdbc-url: jdbc:postgresql://localhost:5432/demodb
and I get this error
FATAL: database "demodb" does not exist
To create database "demodb" with the psql shell was the only way to avoid this error but,
I want to be able to use the container's database, and I believed that the psql shell would have visibility to what was created inside my container.
The screenshot here proves otherwise (Left is the shell). (Right is the container)
All logins (for container and the shell) are identical yet entering psql -U postgres in the command prompt leads to my localhost psql.
When I use \conninfo, my shell's databases are connected to "localhost" (address "::1") at port "5432" while the container databases are connected via socket in "/var/run/postgresql" at port "5432".
Changing my jdbc to jdbc-url: jdbc:postgresql://var/run/postgresql:5432/demodb did not work aswell.
Is it because I have two different psqls on my computer?
答案1
得分: 1
作为对我自己问题的回答,对于那些想要连接到 Docker 容器数据库的人来说,必须确保停止任何 Postgresql 12 服务。
起初,我的连接在容器 IP 处被拒绝,但我可以通过终端连接。我的 Postgres 数据库管理系统也在本地。
英文:
As an answer to my own question, those who want to have a jdbc url connecting to a docker container database, one must make sure to stop any Postgresql 12 service.
Initially, my connection was refused at my container IP but I could connect via terminal. My postgres dbms was in localhost too.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论