gpt4 book ai didi

postgresql - 无法运行 jhipster webapp 的 docker 图像

转载 作者:行者123 更新时间:2023-11-29 13:23:37 25 4
gpt4 key购买 nike

我有一个带有 postgress 数据库的 jhipster 单体网络应用。我使用

构建了一个 docker 镜像
./gradlew bootRepackage -Pprod buildDocker

现在,当我尝试使用 docker run 运行图像时,它失败并出现以下错误。

Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:247)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)

我尝试了一些类似的东西,但仍然得到同样的错误:

docker create -v /var/lib/postgresql/data --name spring_app_data postgres:9.5.1

docker run --volumes-from spring_app_data --name spring_app_pg -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -d -P postgres:9.5.1

docker run -it --link spring_app_pg:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

docker run --name spring_app_container --link spring_app_pg:spring_app_pg -p 8080:8080 -d wmd_server_pg

关于如何使用 PostgreSQL 为 webapp 运行 docker 镜像的任何建议。顺便说一句,我在使用 mongodb 时遇到了同样的错误。

最佳答案

按照您的示例命令,您的数据库将无法从应用程序作为 localhost 访问,它将通过指定的容器访问。配置您的应用程序数据库连接以使用 spring_app_pg:5432

另外,不要使用链接。使用 user defined network ,您很可能只需要一座桥。

docker network create my_app
docker run --net=my_app --name=spring_app_pg <dbimage>
docker run --net=my_app --name=spring_app_container <appimage>

这应该会为您提供与链接设置相同的结果。

关于postgresql - 无法运行 jhipster webapp 的 docker 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37604118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com