I have a spring application using H2 persistent DB with a file located on my machine.
If I run the application outside of the docker container the DB is not empty. If I run the application in docker the database becomes empty. I read this post: Connecting to an H2 Database in a Docker Container and try to add volumes. From what I understand, the docker can persist a local DB file in a container with volumes. But seems like I haven't made it work because the DB is still empty. Can anyone help me?
application.properties
spring.datasource.url=jdbc:h2:./TESTDB/test
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto= update
spring.h2.console.enabled=true
spring.h2.console.path=/h2-ui
spring.h2.console.settings.web-allow-others=true
Dockerfile
FROM azul/zulu-openjdk-alpine:11
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
I run the container like this:
docker run -v ./TESTDB:/TESTDB -p 8080:8080 test-container