docker Spring App容器无法通过服务名称访问另一个容器中的数据库

ee7vknir  于 2023-03-22  发布在  Docker
关注(0)|答案(1)|浏览(108)

我试着用docker compose启动spring app和postgres数据库。我想我可以配置像jdbc:postgresql://db:5432/testdb这样的spring数据源。但是出于某种原因spring不喜欢它。
控制台日志:

web-app  | 2023-03-19 20:31:10.305 ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
web-app  | 
web-app  | org.postgresql.util.PSQLException: The connection attempt failed.
web-app  |      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:331) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.Driver.makeConnection(Driver.java:402) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.Driver.connect(Driver.java:261) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:48) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:75) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:147) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.flywaydb.core.Flyway.migrate(Flyway.java:124) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at com.devmb.ww2db.Ww2dbApplication.main(Ww2dbApplication.java:23) ~[classes!/:0.0.1-SNAPSHOT]
web-app  |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
web-app  |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
web-app  |      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
web-app  |      at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
web-app  |      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[app.jar:0.0.1-SNAPSHOT]
web-app  |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[app.jar:0.0.1-SNAPSHOT]
web-app  |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[app.jar:0.0.1-SNAPSHOT]
web-app  |      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[app.jar:0.0.1-SNAPSHOT]
web-app  | Caused by: java.net.SocketTimeoutException: Connect timed out
web-app  |      at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546) ~[na:na]
web-app  |      at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597) ~[na:na]
web-app  |      at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:331) ~[na:na]
web-app  |      at java.base/java.net.Socket.connect(Socket.java:630) ~[na:na]
web-app  |      at org.postgresql.core.PGStream.createSocket(PGStream.java:241) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.PGStream.<init>(PGStream.java:98) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:109) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      ... 44 common frames omitted
web-app  | 
web-app  | 2023-03-19 20:31:10.310  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: The connection attempt failed.
web-app  | -------------------------------------------------------------------------
web-app  | SQL State  : 08001
web-app  | Error Code : 0
web-app  | Message    : The connection attempt failed.
web-app  | 
web-app  | 2023-03-19 20:31:10.315  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
web-app  | 2023-03-19 20:31:10.331  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 
web-app  | 
web-app  | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
web-app  | 2023-03-19 20:31:10.358 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
web-app  | 
web-app  | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: The connection attempt failed.
web-app  | -------------------------------------------------------------------------
web-app  | SQL State  : 08001
web-app  | Error Code : 0
web-app  | Message    : The connection attempt failed.
web-app  | 
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.8.jar!/:2.7.8]
web-app  |      at com.devmb.ww2db.Ww2dbApplication.main(Ww2dbApplication.java:23) ~[classes!/:0.0.1-SNAPSHOT]
web-app  |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
web-app  |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
web-app  |      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
web-app  |      at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
web-app  |      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[app.jar:0.0.1-SNAPSHOT]
web-app  |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[app.jar:0.0.1-SNAPSHOT]
web-app  |      at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[app.jar:0.0.1-SNAPSHOT]
web-app  |      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[app.jar:0.0.1-SNAPSHOT]
web-app  | Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: The connection attempt failed.
web-app  | -------------------------------------------------------------------------
web-app  | SQL State  : 08001
web-app  | Error Code : 0
web-app  | Message    : The connection attempt failed.
web-app  | 
web-app  |      at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:60) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:75) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:147) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.flywaydb.core.Flyway.migrate(Flyway.java:124) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-2.7.8.jar!/:2.7.8]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.25.jar!/:5.3.25]
web-app  |      ... 26 common frames omitted
web-app  | Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
web-app  |      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:331) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.Driver.makeConnection(Driver.java:402) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.Driver.connect(Driver.java:261) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
web-app  |      at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:48) ~[flyway-core-8.5.13.jar!/:na]
web-app  |      ... 32 common frames omitted
web-app  | Caused by: java.net.SocketTimeoutException: Connect timed out
web-app  |      at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546) ~[na:na]
web-app  |      at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597) ~[na:na]
web-app  |      at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:331) ~[na:na]
web-app  |      at java.base/java.net.Socket.connect(Socket.java:630) ~[na:na]
web-app  |      at org.postgresql.core.PGStream.createSocket(PGStream.java:241) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.PGStream.<init>(PGStream.java:98) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:109) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235) ~[postgresql-42.3.8.jar!/:42.3.8]
web-app  |      ... 44 common frames omitted
web-app  | 
web-app exited with code 1

我的docker-compose.yml如下:

version: '3.8'
volumes:
  postgres_data:
    driver: local
services:
  app:
    build: .
    container_name: web-app
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/testdb
      SPRING_DATASOURCE_USERNAME: postgres
      SPRING_DATASOURCE_PASSWORD: postgres
    ports:
      - "8080:8080"
    depends_on:
      - db
  db:
    image: postgres:alpine3.17
    container_name: db
    restart: always
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: testdb
      PGDATA: /var/lib/postgresql/data/pgdata

为了测试的目的,我在docker-compose中添加了一个服务来ping数据库容器:

services:
  debug:
    image: alpine:latest
    container_name: debug
    stdin_open: true 
    tty: true
    depends_on:
      - db

我认为数据库必须可用:

sudo docker exec -it debug ping db
PING db (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.255 ms

我还尝试在www.example.com中硬编码数据源、登录名和密码application.properties,但没有帮助。
从本地机器(只是为了测试),我可以通过以下URL访问数据库jdbc:postgresql://localhost:5432/testdb
数据库启动日志

db       | 
db       | PostgreSQL Database directory appears to contain a database; Skipping initialization
db       | 
db       | 2023-03-19 20:23:26.503 UTC [1] LOG:  starting PostgreSQL 15.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
db       | 2023-03-19 20:23:26.503 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db       | 2023-03-19 20:23:26.503 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db       | 2023-03-19 20:23:26.506 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db       | 2023-03-19 20:23:26.509 UTC [23] LOG:  database system was interrupted; last known up at 2023-03-19 20:22:49 UTC
db       | 2023-03-19 20:23:26.549 UTC [23] LOG:  database system was not properly shut down; automatic recovery in progress
db       | 2023-03-19 20:23:26.551 UTC [23] LOG:  redo starts at 0/1A65AA0
db       | 2023-03-19 20:23:26.551 UTC [23] LOG:  invalid record length at 0/1A65AD8: wanted 24, got 0
db       | 2023-03-19 20:23:26.551 UTC [23] LOG:  redo done at 0/1A65AA0 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
db       | 2023-03-19 20:23:26.554 UTC [21] LOG:  checkpoint starting: end-of-recovery immediate wait
db       | 2023-03-19 20:23:26.561 UTC [21] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.003 s, sync=0.001 s, total=0.009 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB
db       | 2023-03-19 20:23:26.564 UTC [1] LOG:  database system is ready to accept connections

UPD-2:application.properties

spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
spring.flyway.enabled=true

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://db:5432/testdb
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driver-class-name=org.postgresql.Driver

什么是错与我的docker组成文件?为什么不能我的Spring应用程序到达数据库由服务名称?

ssm49v7z

ssm49v7z1#

在另一台服务器上一切正常。似乎问题出在本地机器上。我无法确定问题。

相关问题