Skip to content

Database

dpl splits databases into two unit types:

  • db-server runs the engine container.
  • db creates one database and one login user inside a db-server.

This lets several apps use separate databases on one engine server.

type: db-server
engine: postgresql
version: 18-alpine
secret: db-server-password

Fields:

FieldRequiredPurpose
engineYespostgresql, mariadb, or mysql.
versionNoImage tag for the default engine image.
imageNoFull image name. Overrides version.
secretYesSecret that stores the root or superuser password.

Default images:

EngineDefault image
postgresqldocker.io/library/postgres:18-alpine
mariadbdocker.io/library/mariadb:12
mysqldocker.io/library/mysql:8.4
type: db
server: db-main
user: app
secret: app-db-password

Fields:

FieldRequiredPurpose
serverYesThe db-server unit name.
userYesLogin user for this database.
secretYesSecret that stores this user’s password.

The database name is the db unit name.

Use these values in app config:

runtime:
env:
DB_NAME: ${app-db:name}
DB_USER: ${app-db:user}
DB_PASSWORD: ${app-db:password}
DB_HOST: ${app-db:host}
DB_PORT: ${app-db:port}
DB_URL: ${app-db:url}

Available keys:

KeyValue
nameDatabase name.
userDatabase login user.
passwordDecrypted user password.
hostThe db-server container name (dpl--<server>). Apps reach it as a hostname on the dpl network.
portEngine port, such as 5432 or 3306.
urlConnection URL. The password is percent-encoded, so the URL is safe to use as is.

Create the server and database:

Terminal window
dpl deploy db-main
dpl deploy app-db

Restore when creating the database:

Terminal window
dpl deploy app-db ./backup.sql
dpl deploy app-db ./backup.sql.gz
gunzip -c backup.sql.gz | dpl deploy app-db -

dpl refuses to restore into an existing database. Drop or rename the database first.