Postgresql docker compose启动时如何创建数据库表并在postgres DB中插入数据
我有一个spring boot应用程序,它被正确配置为在localhost的Postgres上工作。我在Spring引导资源目录中有schema.sql和data.sql。当我启动时,它会创建表并插入数据。但现在我想为我的应用程序和Postgres数据库制作docker容器。我有以下docker-compose.yml。容器的构建和开始都很好。但它不会创建任何表,当然,也不会插入任何数据。那个么我如何通过docker compose创建表并插入数据呢Postgresql docker compose启动时如何创建数据库表并在postgres DB中插入数据,postgresql,spring-boot,docker,docker-compose,Postgresql,Spring Boot,Docker,Docker Compose,我有一个spring boot应用程序,它被正确配置为在localhost的Postgres上工作。我在Spring引导资源目录中有schema.sql和data.sql。当我启动时,它会创建表并插入数据。但现在我想为我的应用程序和Postgres数据库制作docker容器。我有以下docker-compose.yml。容器的构建和开始都很好。但它不会创建任何表,当然,也不会插入任何数据。那个么我如何通过docker compose创建表并插入数据呢 version: "3" services:
version: "3"
services:
postgres:
image: postgres:latest
network_mode: bridge
container_name: postgres
expose:
- 5432
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=dev
- POSTGRES_USER=masi
- POSTGRES_DB=testdb
restart: unless-stopped
# APP
profile_editor:
build:
context: .
dockerfile: ./Dockerfile
network_mode: bridge
container_name: profile_editor
volumes:
- ./image:/app/image
expose:
- 8080
ports:
- 8080:8080
restart: unless-stopped
depends_on:
- postgres
links:
- postgres
他们有错误吗?你有使用任何个人资料的信息吗?不,我没有。只是不知道我是否作为本地主机从应用程序容器连接到bd容器。仍在学习Docker应用程序容器是否确实成功连接到数据库(它不是
localhost
)?如果它不是localhost,它是什么?如果它不是localhost,它是什么?是否有任何错误?你有使用任何个人资料的信息吗?不,我没有。只是不知道我是否作为本地主机从应用程序容器连接到bd容器。仍在学习Docker应用程序容器是否确实成功连接到数据库(它不是localhost
)?如果不是localhost,它是什么?如果不是localhost,它是什么?