不能运行jhipster webapp的docker镜像

我有一个与postgress数据库的jgster单片web应用程序。 我build立了一个docker图像使用

./gradlew bootRepackage -Pprod buildDocker 

现在,当我尝试运行docker运行图像 ,它跟随错误失败。

 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运行Web应用程序的Docker镜像的build议。 顺便说一句,当我使用mongodb时,会出现同样的错误。

通过你的示例命令,你的数据库将不能作为应用程序的localhost访问,它将通过指定的容器。 configuration您的应用程序数据库连接以使用spring_app_pg:5432

另外,不要使用链接。 使用用户定义的networking ,最有可能的桥梁是你所需要的。

 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> 

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