为了学习Docker,我创建了一个小的SpringBoot应用程序,可以创建/列出/更新用户.
我在端口5432上运行一个PostgreSQL数据库,在端口8081上运行我的应用程序.问题是,当我try 启动容器和我的应用程序时:
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 run --name postgres --network demo-network -p 5432:5432 -e POSTGRES_PASSWORD=admin -d postgres
docker run --network demo-network -p 8081:8081 -d myuser/demodocker
我的Spring Boot应用程序.属性:
server.port=8081
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=admin
spring.jpa.hibernate.ddl-auto=drop-and-create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
javax.persistence.schema-generation.scripts.action=drop-and-create
要解决什么问题才能让它发挥作用?