Detailed deployment guide
This guide explains the production settings behind Wonkru MDM: public addresses, secrets, the Docker image, reverse proxy, and device agent. For the standard Docker Compose installation on one server, follow Install first. The same steps work on a rented VPS or a server you own. This page also covers using the image with your own proxy.
3.1 Target architecture
Section titled “3.1 Target architecture”flowchart LR
Browser[Browser] --> Caddy["Caddy<br/>public sites and TLS from .env"]
Device[Android device] --> Caddy
Caddy --> ApiSite[API site]
Caddy --> WebSite[Web site]
subgraph Server["Wonkru MDM server · one instance"]
API["API :8080<br/>RPC and WebSocket device stream"]
Web["Web :8082<br/>panel and file routes"]
end
ApiSite --> API
ApiSite -- "/storage/* and /downloads/*" --> Web
WebSite --> Web
API --> DB[(PostgreSQL :5432)]
API --> Storage[("/app/storage<br/>persistent volume")]
Web --> Storage
- The site addresses and TLS come from
.env. The ready-image HTTP and HTTPS overrides publish only the ports each mode uses. Both installation paths use the same Caddyfile. The API site also proxies/storage/*and/downloads/*to the web server, so a device can fetch the CA and files from the same origin as its server address. - The server must run as a single instance. Device connection registration and rate limit counters are in process memory; with horizontal scaling, push and limits operate per instance.
- Redis is not used.
- The device stream is a WebSocket; the proxy must pass the
Upgrade/Connectionheaders through and keep the timeout high on long-lived connections.
3.2 config/production.yaml
Section titled “3.2 config/production.yaml”If you run the image without deploy/vps/, replace the *.mdm.example.com placeholders in
production.yaml. The VPS Compose setup overrides public addresses, origins and database
connection settings from .env:
| Field | Value |
|---|---|
apiServer.publicHost |
The external name of the API (the panel and the agent connect to it) |
webServer.publicHost |
The name that serves the panel and downloads. The APK/file/certificate URLs in the policy are generated from this; devices must be able to reach this name |
database.host |
PostgreSQL address (requireSsl: true by default) |
allowedOrigins |
The panel’s exact browser origin (the PANEL_ORIGIN value, e.g. https://app.example.com or http://192.168.1.5:8082, no trailing /) |
authCookie.secure: true is on in production; the panel only runs over HTTPS. In the
deploy/vps/ setup this is overridden by SERVERPOD_AUTH_COOKIE_SECURE (true on HTTPS,
false on plain HTTP). Otherwise the browser will not send the cookie. If the origin is
not in the list, login silently fails; if the list is empty, the server does not start.
3.3 Building the Docker image from source
Section titled “3.3 Building the Docker image from source”The image is built from the root:
bash deploy/fetch-agent-apk.shdocker build -f wonkru_mdm_server/Dockerfile -t wonkru-mdm-server .The fetch script uses the signed APK prepared locally or downloads it from a GitHub Release.
Set WONKRU_AGENT_TAG to select a release. deploy/vps/deploy.sh runs this step for you.
The build stage sets up a minimal workspace containing wonkru_core_server and
wonkru_mdm_server, produces bin/server with dart build cli; the final image is alpine. The
root .dockerignore keeps the panel, agent, client packages, build outputs, the local storage/,
.serverpod/ and config/passwords.yaml out of the build context. Secrets do not enter the
image; they are supplied via environment variables (3.4).
The ENTRYPOINT starts with --apply-migrations: pending migrations are applied on every boot.
The panel is copied into the image as the web/app folder. This folder is not committed to git; it
must be built before the image:
cd wonkru_mdm_server && serverpod run flutter_buildThe image’s fixed environment: runmode=production, serverid=default, logging=normal,
role=monolith, STORAGE_PATH=/app/storage. Exposed ports are 8080, 8081, 8082. Insights (8081)
is only needed for the Serverpod Insights app; exposing it externally is not required.
3.4 Environment variables and secrets
Section titled “3.4 Environment variables and secrets”Required:
| Variable | Why |
|---|---|
SERVERPOD_PASSWORD_database |
DB password |
SERVERPOD_PASSWORD_serviceSecret |
Serverpod service secret |
SERVERPOD_PASSWORD_emailSecretHashPepper |
Pepper for panel user passwords |
SERVERPOD_PASSWORD_jwtHmacSha512PrivateKey |
JWT signing |
SERVERPOD_PASSWORD_jwtRefreshTokenHashPepper |
Refresh token pepper |
PASSWORD_HASH_PEPPER |
Policy password, 2FA recovery codes and TOTP encryption |
SERVERPOD_PASSWORD_storageSigningKey |
Signed download links (≥32 characters). If not provided, it is derived from the JWT key and a warning is written on startup |
APP_URL |
The server_url in the QR code; the API public address the agent connects to (scheme://host:port, matched to API_PUBLIC_*) |
Depending on the situation:
| Variable | When |
|---|---|
CLIENT_IP_SOURCE=proxy (or cloudflare) |
Behind a reverse proxy. If not provided, all clients appear to come from the proxy IP and IP-based limits (login, enrollment) cut off everyone together |
APP_NAME |
Brand name fallback |
LOCAL_CA_PATH |
When the CA file for a self-signed TLS is elsewhere |
MAIL_* |
Fallback values used when the SMTP fields in the panel are empty |
Full list: Configuration reference.
The deploy/vps/ compose derives the server’s public endpoints from
API_PUBLIC_SCHEME/HOST/PORT, WEB_PUBLIC_SCHEME/HOST/PORT, PANEL_ORIGIN and APP_URL,
and maps AUTH_COOKIE_SECURE to SERVERPOD_AUTH_COOKIE_SECURE (see Deployment modes).
3.5 Running
Section titled “3.5 Running”Example:
docker run -d --name wonkru-mdm \ -p 127.0.0.1:8080:8080 -p 127.0.0.1:8082:8082 \ -v wonkru_storage:/app/storage \ -v /srv/wonkru/certs:/app/certs:ro \ --env-file /srv/wonkru/server.env \ wonkru-mdm-server/app/storagemust be a persistent volume. Otherwise APKs, certificates and files are lost when the container is recreated.- This example binds API and web ports to loopback because the reverse proxy runs on the same host.
- Health endpoints: Serverpod’s
/livez,/readyz,/startupzendpoints; readiness checks the database, storage, scheduled jobs and SMTP configuration.
Reverse proxy
Section titled “Reverse proxy”For an Nginx reverse proxy, route the API site to port 8080 and its download paths to the web server on port 8082. Configure a separate HTTPS server block for the panel on port 8082. This excerpt needs your TLS certificate paths:
server { listen 443 ssl; server_name api.mdm.example.com; # ssl_certificate ...
client_max_body_size 300m; # maxRequestSize 288 MB proxy_read_timeout 3600s; # the device stream lives long
location ^~ /storage/ { proxy_pass http://127.0.0.1:8082; proxy_set_header Host $host; }
location ^~ /downloads/ { proxy_pass http://127.0.0.1:8082; proxy_set_header Host $host; }
location / { proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }}# Configure the panel hostname separately and proxy it to 127.0.0.1:8082.For an internet-facing deployment, use a certificate issued by a CA that browsers and Android already trust. For a local network with your own CA, follow the guide for configuring the server and enrolling devices. HTTPS with your own TLS certificate
Wonkru MDM serves the PEM file configured in LOCAL_CA_PATH at /downloads/local-ca.
Caddy forwards /downloads/* and /storage/* on the API site to the web server. With a
private CA, you can open a separate HTTP listener for the certificate file alone.
3.6 First admin setup
Section titled “3.6 First admin setup”- Before running the installer, restrict the API and panel to your IP address or trusted network. Use your hosting provider’s firewall or a VPN.
- Create the first admin, enable 2FA, and save the recovery codes.
- Widen access to the people and devices that need it.
Other admins are added from the panel (Users). Someone who self-registers via the email IDP
does not become an admin; admin endpoints require an active AdminProfile.
3.7 Email
Section titled “3.7 Email”SMTP must be enabled from the panel (Settings → SMTP) for account registration and password reset codes
to be sent on your own server. If there is no SMTP setting, the server tries Serverpod Cloud email;
this requires scloudAuthEmailKey and does not exist outside Serverpod Cloud. Verify with the test
mail on the Settings screen.
3.8 Panel
Section titled “3.8 Panel”The panel is served from the server’s web address (WEB_PUBLIC_*) and learns the API address at
runtime via /assets/assets/config.json. If it will be hosted on a separate static server, see
Admin panel.
3.9 Agent APK
Section titled “3.9 Agent APK”The Docker installation already includes a signed APK. Download it from the dashboard. The default Wonkru MDM provisioning profile fills in the APK URL, file checksum, API address and enrollment key from the current installation.
To build your own agent, configure wonkru_mdm_mobil/android/key.properties and run
the following command from wonkru_mdm_mobil:
WONKRU_REQUIRE_RELEASE_SIGNING=true flutter build apk --release --dart-define=WONKRU_PUBLIC_AGENT=trueUpload the APK as a new version under Applications. For a different package, create an application and select it under Settings → MDM APK package name. If your build has a different Device Admin receiver class, set that class in the provisioning profile.
Changing the download version only affects future downloads and provisioning. To update
enrolled devices, upload an APK with the same package and signing key and a higher
versionCode, then select it in the device policy.
3.10 Deployment checklist
Section titled “3.10 Deployment checklist”- Public addresses and
allowedOriginsmatch the deployment (.envfor VPS,production.yamlotherwise) - All secrets in environment variables;
passwords.yamlnot in the image -
PASSWORD_HASH_PEPPERand the storage signing key provided and backed up - Panel built as
web/app -
/app/storagepersistent volume - Proxy passes the WebSocket,
CLIENT_IP_SOURCE=proxy - First admin set up while access was restricted, 2FA on
- SMTP configured and test mail received
- Time zone and default policy set in the panel
- Agent signed with the release key; APK address and checksum in the QR filled in
- Verify the enrollment → command → policy flow on a test device
3.11 Docker Compose files and deployment modes (deploy/vps/)
Section titled “3.11 Docker Compose files and deployment modes (deploy/vps/)”Both installation paths run PostgreSQL 16, the Wonkru MDM server, and Caddy.
| File | Role |
|---|---|
docker-compose.yaml |
Shared services, health checks, and volumes |
docker-compose.build.yaml |
Builds the server image on the VPS for source deployments |
docker-compose.http.yaml |
Uses the published image and publishes only the HTTP API and panel ports |
docker-compose.https.yaml |
Uses the published image and publishes Caddy ports 80 and 443 |
Caddyfile |
TLS, WebSocket forwarding, and the API site’s /storage/* and /downloads/* routes |
.env.example and init-env.sh |
Public addresses, ports, and generated secrets |
The Linux installer uses /opt/wonkru-mdm and the Compose project name wonkru-mdm-image.
New source deployments go to /opt/wonkru-mdm-source, with settings in
/opt/wonkru-mdm-source/deploy/vps/.env. The source path keeps the wonkru-mdm project name.
When updating an older source installation, pass its existing path to deploy.sh.
Build from source
Section titled “Build from source”On your computer, install Flutter, Serverpod CLI 4.1.2, rsync and OpenSSL. On the VPS,
install Docker with Compose. Generate deploy/vps/.env from your checkout and set
your addresses before the first deployment. For TLS settings, see Deployment modes.
(cd deploy/vps && ./init-env.sh SERVER_IP)ssh root@SERVER_IP "mkdir -p /opt/wonkru-mdm-source/deploy/vps"scp -p deploy/vps/.env root@SERVER_IP:/opt/wonkru-mdm-source/deploy/vps/.env./deploy/vps/deploy.sh root@SERVER_IPReplace SERVER_IP with the target address. The script builds the Flutter panel locally, sends the
source and panel to the VPS, then builds the server image with Docker. Run the last command
again to deploy changes. For older source installations, pass their existing path explicitly,
for example ./deploy/vps/deploy.sh root@SERVER_IP /opt/wonkru-mdm. Protect the source stack’s
published ports at the network edge as needed.
Manual installation
Section titled “Manual installation”Restrict access for the first admin
before starting. Use Docker Compose 2.24.4 or newer and choose an empty installation directory.
Set VERSION to a published GitHub release.
Replace SERVER_ADDRESS with the address clients will use.
VERSION=vX.Y.ZMODE=httpBASE="https://raw.githubusercontent.com/Aksoyhlc/wonkru_mdm/$VERSION/deploy"for FILE in docker-compose.yaml Caddyfile .env.example init-env.sh; do curl -fsSLO "$BASE/vps/$FILE" || exit 1donecurl -fsSL "$BASE/vps/docker-compose.$MODE.yaml" -o docker-compose.override.yamlcurl -fsSLO "$BASE/install.sh"bash ./init-env.sh SERVER_ADDRESSSet WONKRU_IMAGE=wonkrumdm/wonkrumdm:vX.Y.Z in .env using the selected release.
For HTTP clients on another machine, set HTTP_BIND_IP=0.0.0.0. For HTTPS with domains,
select MODE=https before downloading and configure the HTTPS row below, including
API_PUBLIC_*, WEB_PUBLIC_*, PANEL_ORIGIN, APP_URL, AUTH_COOKIE_SECURE, and ACME_EMAIL.
docker compose pulldocker compose up -d --waitAfter editing settings within the same mode, run docker compose up -d. To switch between
HTTP and HTTPS, save the matching port file from your installed release as
docker-compose.override.yaml and update the corresponding addresses in .env.
The ready-image HTTPS override uses fixed ports 80 and 443. Use your own override for
custom port layouts.
Before changing versions, back up PostgreSQL,
/app/storage, and .env. You can run bash ./install.sh update from a manually installed
stack, as root on Linux. docker compose down -v deletes the persistent volumes.
Deployment modes
Section titled “Deployment modes”The source deployment publishes the four port mappings in the base file. The ready-image
HTTP override uses only API_PORT and WEB_PORT. The HTTPS override publishes 80 and 443.
The relevant keys are API_PUBLIC_SCHEME/HOST/PORT and
WEB_PUBLIC_SCHEME/HOST/PORT (public endpoints), PANEL_ORIGIN, APP_URL, the Caddy sites
API_SITE / WEB_SITE / BRIDGE_SITE / CADDY_TLS, and the host ports HTTP_PORT /
HTTPS_PORT / API_PORT / WEB_PORT (mapped to the fixed container ports 80 / 443 / 8080 /
8082; all must be distinct).
| Mode | Public endpoints | Caddy |
|---|---|---|
| Single host + HTTP + ports | http://HOST:8080, http://HOST:8082 |
API_SITE=http://:8080, WEB_SITE=http://:8082, CADDY_TLS= |
| Single host + HTTPS + ports | https://HOST:8443, https://HOST:8444 |
API_SITE=https://:8080, WEB_SITE=https://:8082, CADDY_TLS="tls internal" (or a provided cert) |
| Domain + HTTPS (Let’s Encrypt) | https://api.example.com, https://app.example.com |
API_SITE=https://api.example.com, WEB_SITE=https://app.example.com, CADDY_TLS=, ACME_EMAIL required |
| Domain + HTTP | http://api.example.com, http://app.example.com |
API_SITE=http://api.example.com, WEB_SITE=http://app.example.com, CADDY_TLS= |
Subdomains are optional; the domain rows are examples. PANEL_ORIGIN must equal
the WEB_PUBLIC_* origin exactly and APP_URL must equal the API_PUBLIC_* origin. Set
AUTH_COOKIE_SECURE=true on HTTPS and false on HTTP. The optional BRIDGE_SITE exposes the
API and downloads on a single extra port for local/USB device setup; it is unmapped by default.
For the complete installation sequence on an Ubuntu or Debian server, use the installation guide.