【发布时间】:2016-05-27 11:46:02
【问题描述】:
尝试使用 Tomcat 的 PersistentManager 将会话数据写入本地计算机上运行的 Postgres DB 时,我收到以下错误:
SEVERE: A SQL exception occurred 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.
应用程序本身在 docker 容器中运行。为了完整起见,我当前的 context.xml 文件是:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<Manager className="org.apache.catalina.session.PersistentManager"
distributable="true" processExpiresFrequency="6" maxIdleBackup="0" debug="99" >
<Store className="org.apache.catalina.session.JDBCStore"
driverName="org.postgresql.Driver"
connectionURL="jdbc:postgresql://localhost/admin?stringtype=unspecified"
connectionName="admin" connectionPassword="admin"
sessionAppCol="app_name" sessionDataCol="session_data" sessionIdCol="session_id"
sessionLastAccessedCol="last_access" sessionMaxInactiveCol="max_inactive"
sessionTable="tomcat_sessions_tb" sessionValidCol="valid_session" />
</Manager>
</Context>
我通过netstat -aln | grep LISTEN 确认 Postgresql 正在运行并侦听正确的端口:
tcp4 0 0 127.0.0.1.5432 *.* LISTEN
tcp6 0 0 ::1.5432 *.* LISTEN
而且我的 postgresql.conf(位于 usr/local/var/postgres)有 listen_addresses = localhost 和 port = 5432,这反映了我在 Pgadmin3 中运行的服务器的主机和端口。
我怀疑问题在于 Docker 在 VM 中运行,因此我获得的本地信息可能不是全部。在线阅读可用信息,看来我可能需要某种桥接网络。
但是,我承认我是这方面的新手,我不确定如何设置它。
【问题讨论】:
-
我已经转移到 memcached,并且遇到了几乎相同的错误。我现在确信这是桥接,但我不确定如何从 Docker 方面处理它。
标签: postgresql tomcat docker