更新时间:2023-09-12 23:46:34
每个容器都有自己的网络接口和本地主机。因此,更改Java指向Postgres的方式:
Each container has its own network interface with its own localhost. So change how Java points to Postgres:
spring.datasource.url=jdbc:postgresql://localhost:5432/sample
收件人:
spring.datasource.url=jdbc:postgresql://db:5432/sample
db
将解析为正确的Postgres IP。
db
will resolve to the proper Postgres IP.
奖金。使用docker-compose,您无需手动构建图片。因此更改:
Bonus. With docker-compose you don't need to build your image by hand. So change:
web:
image: myuser/manager:latest
收件人:
web:
build: .