springboot dockerfile dockercompose postgres错误“localhost:5432 refused"

ux6nzvsh  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(422)

我的dockerfile和docker compose连接到我的postgres(容器)有问题。这是我的错误 Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. 这是我的财产

spring.datasource.url=jdbc:postgresql://postgres-db:5432/offer
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driverClassName=org.postgresql.Driver

spring.jpa.hibernate.ddl-auto=create-drop
logging.level.org.hibernate.sql=DEBUG
logging.level.org.hibernate.type.descriptor.sql=trace
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

# spring.jpa.hibernate.ddl-auto=none

springdoc.api-docs.path=/api-docs

# server.port=8085

spring.devtools.restart.log-condition-evaluation-delta=false

我的dockerfile

FROM openjdk:8-jdk-alpine
EXPOSE 8085
VOLUME /tmp
ADD target/weShareJob-service-offer-0.0.1-SNAPSHOT.jar offer.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container", "-jar", "offer.jar"]

Docker

version: "3"
services:
  postgres-db:
    image: postgres:latest
    network_mode: bridge
    container_name: postgres-db
    volumes:
      - postgres-data:/var/lib/postgresql/data
    expose:
      - 5432
    ports:
      - 5432:5432
    environment:
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_DB=offer
    restart: unless-stopped
  # APP*****************************************
  offer:
    image: offer:latest
    network_mode: bridge
    container_name: offer
    expose:
      - 8085
    ports:
      - 8085:8085
    restart: unless-stopped
    depends_on:
      - postgres-db
    links:
      - postgres-db
volumes:
  postgres-data:

我不明白为什么我的错误是“我尝试连接”localhost:5432“或者我在我的url中传递了postgres db。我已经核对了与我相似的问题的其他答案。
感谢您的帮助:)

wd2eg0qa

wd2eg0qa1#

我看到你的申请是从

-Dspring.profiles.active=container

所以我想知道您的应用程序属性如何查找配置文件容器?
你确定容器配置文件启动了吗(你签入输出了吗?)

相关问题