My application is running but the docker-compose is not creating the tables for me in my postgres docker container. At a loss for this at this point. Below is my relevant code
docker-compose
version: '3.8'
services:
db:
image: postgres:17
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mydb
ports:
- "5432:5432" # Optional, expose port for external access (e.g., pgAdmin)
volumes:
- postgres-data:/var/lib/postgresql/data # Persist data
app:
build:
context: . # Assumes your Dockerfile is in the same directory
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/mydb
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: postgres
SPRING_R2DBC_URL: r2dbc:postgresql://db:5432/mydb
SPRING_R2DBC_USERNAME: postgres
SPRING_R2DBC_PASSWORD: postgres
SPRING_JPA_HIBERNATE_DDL_AUTO: create # Or validate, create, update, create-drop. Adjust for production.
depends_on:
- db
volumes:
postgres-data:
I also have a schema.sql under my resources but it seems to be ignored also
schema.sql
CREATE TABLE IF NOT EXISTS stocks (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
I have tried various configurations of docker-compose with no luck. If I manually add my table in postgres my code works correctly. I want it to create tables on start up and it is not doing it.
My application is running but the docker-compose is not creating the tables for me in my postgres docker container. At a loss for this at this point. Below is my relevant code
docker-compose
version: '3.8'
services:
db:
image: postgres:17
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mydb
ports:
- "5432:5432" # Optional, expose port for external access (e.g., pgAdmin)
volumes:
- postgres-data:/var/lib/postgresql/data # Persist data
app:
build:
context: . # Assumes your Dockerfile is in the same directory
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/mydb
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: postgres
SPRING_R2DBC_URL: r2dbc:postgresql://db:5432/mydb
SPRING_R2DBC_USERNAME: postgres
SPRING_R2DBC_PASSWORD: postgres
SPRING_JPA_HIBERNATE_DDL_AUTO: create # Or validate, create, update, create-drop. Adjust for production.
depends_on:
- db
volumes:
postgres-data:
I also have a schema.sql under my resources but it seems to be ignored also
schema.sql
CREATE TABLE IF NOT EXISTS stocks (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
I have tried various configurations of docker-compose with no luck. If I manually add my table in postgres my code works correctly. I want it to create tables on start up and it is not doing it.
postgresql
docker-compose
spring-webflux
Share
Improve this question
asked Mar 5 at 23:15
Beartato327Beartato32711722 silver badges77 bronze badges
Add a comment
|
1 Answer
1
Reset to default
0
may be or not r2dbc not support Hibernate automatic ddl , you can add it into database container .