无法运行jhipster webapp的docker镜像

时间:2016-06-03 00:22:10

标签: postgresql docker jhipster

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

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

现在,当我尝试使用泊坞窗运行 来运行图像时,它会失败并显示以下错误。

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时,我会遇到同样的错误。

1 个答案:

答案 0 :(得分:1)

按照您的示例命令,您的数据库将无法从应用程序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>

这应该会给你与链接设置相同的结果。