#1
Dropwizard is a lightweight, powerful framework for building Java REST services. For simple apps or lightweight persistence needs, SQLite is a perfect match—it’s serverless, fast, and easy to manage. Let’s explore how you can configure SQLite with Dropwizard using Docker for development and Kubernetes for production.

1. Add Dependencies in pom.xml

Include the SQLite JDBC driver and Dropwizard in your build:
<dependencies>
  <!-- Dropwizard core -->
  <dependency>
    <groupId>io.dropwizard</groupId>
    <artifactId>dropwizard-core</artifactId>
    <version>${dropwizard.version}</version>
  </dependency>

  <!-- SQLite JDBC driver -->
  <dependency>
    <groupId>org.xerial</groupId>
    <artifactId>sqlite-jdbc</artifactId>
    <version>3.8.11.2</version>
  </dependency>

  <!-- Kubernetes client (optional) -->
  <dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>kubernetes-client</artifactId>
    <version>${fabric8.version}</version>
  </dependency>
</dependencies>
SQLite JDBC support lets your app connect to a .db file directly.

2. Run SQLite with Docker for Development

SQLite uses a file-based database, so you can host it in a minimal Docker container for isolation:
version: '3.8'
services:
  sqlite:
    image: alpine:latest
    command: ["tail", "-f", "/dev/null"]
    volumes:
      - ./data:/data
Run with:
docker-compose up -d
Place your app.db inside ./data/, making it accessible from the container.

3. Configure Development: config-dev.yml

Setup your Dropwizard config to point at that file:
server:
  applicationConnectors:
    - type: http
      port: 8080

database:
  driverClass: org.sqlite.JDBC
  url: jdbc:sqlite:/data/app.db
  validationQuery: SELECT 1
Map it in Java:
public class DbConfig {
  @JsonProperty public String driverClass;
  @JsonProperty public String url;
  @JsonProperty public String validationQuery;
}

public class AppConfig extends Configuration {
  @JsonProperty("database")
  public DbConfig database;
}
Initialize the datasource:
ManagedDataSource ds = config.database.build(environment.metrics(), "sqlite");
environment.lifecycle().manage(ds);
Launch dev mode:
java -jar target/myapp.jar server config-dev.yml

4. Prepare for Kubernetes in Production

For production, store file path securely via ConfigMaps or Secrets:
kubectl create configmap sqlite-config \
  --from-literal=DB_URL=jdbc:sqlite:/db/app.db

kubectl create persistentvolumeclaim sqlite-pvc --...  # create PVC
The PVC will persist your .db file in Kubernetes.

5. Production Config: config-prod.yml

Use environment variables in production:
server:
  applicationConnectors:
    - type: http
      port: 8080

database:
  driverClass: org.sqlite.JDBC
  url: ${DB_URL}
  validationQuery: SELECT 1

6. Kubernetes Pod Snippet

Connect the PVC and inject config:
env:
  - name: DB_URL
    valueFrom:
      configMapKeyRef:
        name: sqlite-config
        key: DB_URL

volumeMounts:
  - name: sqlite-data
    mountPath: /db
volumes:
  - name: sqlite-data
    persistentVolumeClaim:
      claimName: sqlite-pvc
Start your container with:
java -jar myapp.jar server config-prod.yml
Now your Dropwizard service reads the SQLite file from the mounted path.

7. Key Benefits

  • Simplicity: No external DB server—just a file.
  • Dev speed: Docker isolates it, but simplicity remains.
  • Production readiness: PVC in Kubernetes ensures durability.
  • Secure config: No credentials required, path controlled via ConfigMap.
This approach gives you the best of both worlds: a lightweight SQLite setup for rapid development, and a secure, persistent production environment managed with Kubernetes. With Dropwizard’s solid configuration system, your app can stay consistent across environments with minimal changes—just clean, functional, and fitting for small to medium use cases.

image quote pre code