简体   繁体   English

Docker Compose Tomcat无法连接到Postgresql

[英]Docker Compose Tomcat Can not connect to postgresql

I have 2 containers. 我有2个容器。 One of them postgresql, one of them tomcat. 其中之一是postgresql,其中之一是tomcat。 I tried to start applications but always getting ohejdbc.spi.SqlExceptionHelper - Connection refused. 我尝试启动应用程序,但始终获取ohejdbc.spi.SqlExceptionHelper-连接被拒绝。 Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. 检查主机名和端口是否正确以及邮局主管正在接受TCP / IP连接。 error. 错误。 Please help me i don't have much time. 请帮助我,我没有太多时间。 Best regards. 最好的祝福。

I tried different type of docker composes. 我尝试了不同类型的docker compos。 But i got always same error. 但是我总是遇到同样的错误。

16:48:09.557 [localhost-startStop-1] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

My connection url 我的连接网址

db.user=admin
db.password=123456
db.url=jdbc:postgresql://moneytransferdb:5410/moneytransfer

My docker compose yml 我的泊坞窗撰写yml

version: '3'

services:
  moneytransferdb:
   image: postgres
   restart: always
   ports:
     - "5410:5432"
   volumes:
     - mydatavol:/var/lib/postgresql/data
   environment:
     POSTGRES_USER: admin
     POSTGRES_PASSWORD: 123456
     POSTGRES_DB: moneytransfer
   container_name: moneytransfer
   networks:
     - main
  tomcat:
    image: tomcat
    ports:
     - "8080:8080"
    volumes:
     - ../tcmb/tcmb-service.war:/usr/local/tomcat/webapps/tcmb.war
    container_name: tcmb
    depends_on:
     - moneytransferdb
    links:
     - moneytransferdb
    restart: always
    networks:
     - main
volumes:
  mydatavol: {}
networks:
  main:

Change your connection settings to this: 将连接设置更改为此:

db.user=admin
db.password=123456
db.url=jdbc:postgresql://moneytransferdb:5432/moneytransfer

Port mappings make container ports available to the host but are not used by other containers. 端口映射使容器端口可用于主机,但未被其他容器使用。 For them only container ports matter. 对于他们来说,只有集装箱港口很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM