This guide shows how to package a Spring Boot app using Apache Derby and run it inside Docker for lightweight deployment.
1. Add Dependencies
Inpom.xml:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
2. Configure Derby
Inapplication.properties:
spring.datasource.url=jdbc:derby:/app/data/derbyDB;create=true
spring.datasource.driver-class-name=org.apache.derby.jdbc.EmbeddedDriver
spring.jpa.hibernate.ddl-auto=update
This stores Derby files in /app/data/derbyDB inside the container.
3. Create Dockerfile
In the project root:FROM openjdk:17-jdk-slim
VOLUME /app/data
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
VOLUME /app/data→ persists Derby data outside container lifecycle.
4. Build Docker Image
Package the JAR:mvn clean package -DskipTests
Build Docker image:
docker build -t springboot-derby-app .
5. Run Container
Run app with Derby database:docker run -d -p 8080:8080 -v derby_data:/app/data springboot-derby-app
-p 8080:8080→ exposes API.-v derby_data:/app/data→ persists Derby data on host.
6. Test the API
Use curl to test:curl http://localhost:8080/your-endpoint
The data will remain safe across container restarts thanks to the volume.

image quote pre code