Skip to content

Self-Hosting on Dokploy

Dokploy is an open-source, self-hosted Platform-as-a-Service (PaaS) alternative to Vercel/Heroku/Coolify that runs on top of Docker and Traefik.

Dokploy operators typically deploy KoAkademy in one of two ways—both support zero-interruption updates when configured properly:

Deployment Source Best Dokploy Service Type How Updates Trigger Recommended Migration Strategy
Pre-built Registry Image (Docker Hub or GHCR) Method 1: Compose → Stack (Swarm) Registry update notifications / tag bump + Redeploy (or registry webhook) One-off release migration (AUTO_MIGRATE="false"), or AUTO_MIGRATE="true" with AUTO_MIGRATE_LOCK="true" for webhook redeploys
GitHub Repository (Auto Deploy on push to master) Method 2: Application Services (docker/Dockerfile.franken + Swarm start-first) Automatic build & rollout on every push to master AUTO_MIGRATE="true" + AUTO_MIGRATE_LOCK="true" on the web app service (AUTO_MIGRATE="false" on horizon and scheduler)

You can deploy KoAkademy in Dokploy using either:

  1. Zero-Downtime Docker Stack (Recommended for Docker Hub / GHCR Images): Deploys decoupled services (app for HTTP, horizon for background queues, scheduler for cron) with health-gated start-first updates, automated rollbacks, and tuned resource caps.
  2. Standalone Application Services (Recommended for GitHub Auto Deploy & Managed Databases): Deploys Dokploy managed databases (PostgreSQL & Redis) alongside standalone Application services built from GitHub or pulled from Docker Hub/GHCR with Swarm start-first enabled.

Section titled “Method 1: Zero-Downtime Compose Stack Deployment (Recommended)”

How Zero-Downtime Deployments Work in Dokploy

Section titled “How Zero-Downtime Deployments Work in Dokploy”

By default, Docker Swarm and Compose stop the existing container before starting the new one (order: stop-first), resulting in a brief 502 Bad Gateway error while the new container boots.

To achieve seamless, zero-downtime updates:

  • order: start-first: Docker starts the new container replica alongside the current running container.
  • Container Healthcheck: The internal healthcheck script probes /health (and supervisor processes).
  • VIP Routing Gate: Dokploy and Traefik keep routing user traffic to the old container until the new container reports healthy over the configured monitoring period.
  • Automated Rollback: If the new container fails its health checks during the monitor period, the update rolls back immediately without dropping traffic.
  • Decoupled Workers: The web container runs with HORIZON_IN_HTTP_CONTAINER="false", while Horizon and the scheduler run as dedicated services so queuing is not duplicated or interrupted during start-first web container rollovers.
  • Retained Vite Assets & Soft Browser Updates: On startup (RETAIN_PREVIOUS_BUILD_ASSETS="true"), each new app container copies its hashed /app/public/build/assets/* files additively into the shared app-storage volume (/app/storage/app/build-assets) while keeping manifest.json container-local. Combined with INERTIA_SOFT_VERSION_UPDATES="true", active portal tabs never hit chunk 404s during overlapping rollouts and receive a non-blocking “Update ready” prompt instead of an abrupt 409 hard reload mid-form.
  1. Navigate to your Dokploy dashboard.
  2. Click Create Project and name it koakademy.
  3. Inside the project, click Create Service, select Compose, and choose Stack as the Compose Type.

Paste the following production Compose specification into the Raw Compose editor:

version: "3.8"
services:
app:
image: ghcr.io/yukazakiri/koakademy:latest-franken
env_file:
- .env
environment:
HEALTHCHECK_PATH: /up
HORIZON_IN_HTTP_CONTAINER: "false"
volumes:
- app-storage:/app/storage
networks:
- koakademy
deploy:
replicas: 1
resources:
limits:
memory: 3G
reservations:
memory: 1536M
placement:
constraints:
- node.role == manager
max_replicas_per_node: 2
update_config:
parallelism: 1
delay: 0s
order: start-first
monitor: 120s
failure_action: rollback
rollback_config:
parallelism: 1
order: stop-first
restart_policy:
condition: any
endpoint_mode: vip
healthcheck:
test: ["CMD", "healthcheck"]
interval: 30s
timeout: 10s
start_period: 60s
retries: 5
stop_grace_period: 30s
horizon:
image: ghcr.io/yukazakiri/koakademy:latest-franken
env_file:
- .env
environment:
CONTAINER_MODE: horizon
AUTO_MIGRATE: "false"
RUN_OPTIMIZE: "false"
RUN_SCOUT_SETTINGS: "false"
volumes:
- app-storage:/app/storage
networks:
- koakademy
deploy:
replicas: 1
resources:
limits:
memory: 1G
reservations:
memory: 384M
placement:
constraints:
- node.role == manager
restart_policy:
condition: any
healthcheck:
test: ["CMD", "healthcheck"]
interval: 30s
timeout: 10s
start_period: 60s
retries: 5
stop_grace_period: 30m
scheduler:
image: ghcr.io/yukazakiri/koakademy:latest-franken
env_file:
- .env
environment:
CONTAINER_MODE: scheduler
AUTO_MIGRATE: "false"
RUN_OPTIMIZE: "false"
RUN_SCOUT_SETTINGS: "false"
volumes:
- app-storage:/app/storage
networks:
- koakademy
deploy:
replicas: 1
resources:
limits:
memory: 384M
reservations:
memory: 128M
placement:
constraints:
- node.role == manager
restart_policy:
condition: any
healthcheck:
test: ["CMD", "healthcheck"]
interval: 30s
timeout: 10s
start_period: 60s
retries: 5
stop_grace_period: 30s
pgsql:
image: postgres:18-alpine
environment:
POSTGRES_DB: koakademy
POSTGRES_USER: koakademy
POSTGRES_PASSWORD: ${DB_PASSWORD:?Set DB_PASSWORD in .env}
volumes:
- pgsql-data:/var/lib/postgresql
networks:
- koakademy
deploy:
replicas: 1
resources:
limits:
memory: 512M
reservations:
memory: 128M
placement:
constraints:
- node.role == manager
redis:
image: redis:8-alpine
command:
- redis-server
- --appendonly
- "yes"
- --requirepass
- ${REDIS_PASSWORD:?Set REDIS_PASSWORD in .env}
- --maxmemory
- 384mb
- --maxmemory-policy
- noeviction
volumes:
- redis-data:/data
networks:
- koakademy
deploy:
replicas: 1
resources:
limits:
memory: 448M
reservations:
memory: 128M
placement:
constraints:
- node.role == manager
gotenberg:
image: gotenberg/gotenberg:8
networks:
- koakademy
deploy:
replicas: 1
resources:
limits:
memory: 512M
reservations:
memory: 128M
volumes:
app-storage:
pgsql-data:
redis-data:
networks:
koakademy:
driver: overlay
attachable: true

Under the Environment tab in Dokploy, add your application configuration:

APP_NAME="KoAkademy"
APP_ENV="production"
APP_DEBUG="false"
APP_URL="https://school.example.com"
PORTAL_HOST="school.example.com"
ADMIN_HOST="school.example.com"
TRUSTED_PROXIES="*"
APP_KEY="base64:..." # Generate with: php artisan key:generate --show
# Database
DB_CONNECTION="pgsql"
DB_HOST="pgsql"
DB_PORT="5432"
DB_DATABASE="koakademy"
DB_USERNAME="koakademy"
DB_PASSWORD="StrongDatabasePasswordHere"
# Redis Cache & Queues
CACHE_STORE="redis"
SESSION_DRIVER="redis"
QUEUE_CONNECTION="redis"
REDIS_HOST="redis"
REDIS_PORT="6379"
REDIS_PASSWORD="StrongRedisPasswordHere"
REDIS_DB="0"
REDIS_CACHE_DB="1"
REDIS_QUEUE_DB="2"
REDIS_PDF_QUEUE_DB="3"
# Concurrency & Performance
OCTANE_SERVER="frankenphp"
OCTANE_WORKERS="2"
OCTANE_MAX_REQUESTS="500"
HORIZON_ENABLED="true"
HORIZON_PROCESSES="1"
HORIZON_PDF_PROCESSES="1"
HORIZON_MEMORY="256"
HORIZON_PDF_MEMORY="512"
ASSESSMENT_EXPORT_PROCESSES="1"
ASSESSMENT_EXPORT_EVENT_PROCESSES="1"
ASSESSMENT_EXPORT_WORKER_MEMORY="512"
# Production Hardening
APP_MAINTENANCE_DRIVER="cache"
APP_MAINTENANCE_STORE="redis"
RETAIN_PREVIOUS_BUILD_ASSETS="true"
BUILD_ASSETS_RETENTION_DAYS="7"
INERTIA_SOFT_VERSION_UPDATES="true"
TELESCOPE_ENABLED="false"
PULSE_ENABLED="false"
NIGHTWATCH_ENABLED="false"
LOG_LEVEL="info"
# PDF Engine & Storage
GOTENBERG_URL="http://gotenberg:3000"
LARAVEL_PDF_DRIVER="gotenberg"
LARAVEL_PDF_PRODUCTION_DRIVER="gotenberg"
FILESYSTEM_DISK="public"
  1. In Dokploy’s Domains section, add your domain: school.example.com.
  2. Select service: app, container port: 8000.
  3. Enable HTTPS / SSL Certificate via Let’s Encrypt or Cloudflare.
  4. Click Deploy.

Zero-Downtime Redeployment & Upgrade Runbook

Section titled “Zero-Downtime Redeployment & Upgrade Runbook”

Pre-Built Image Updates (Docker Hub / GHCR)

Section titled “Pre-Built Image Updates (Docker Hub / GHCR)”

When you receive an update notification or pull a new release image (such as ghcr.io/yukazakiri/koakademy:v1.30.0-franken, ghcr.io/yukazakiri/koakademy:latest-franken, or the matching Docker Hub tag):

  1. Run the migrations as a release step (when AUTO_MIGRATE="false"): run the migration once, in a one-off container against the same database, before the rollout starts. Migrations are not part of the container boot, so the application never serves traffic against a schema it does not expect.

    Dokploy runs Compose with -p {appName}, so the project name is given explicitly. Without it, Compose derives the name from the working directory and the one-off container joins a different network, where it cannot reach the pgsql service.

    The image is pulled first with --pull always, so the migration runs on the exact image the rollout starts rather than a cached older release:

    Terminal window
    docker compose -p <dokploy-app-name> --env-file .env -f docker-compose.yml run --rm --pull always app php artisan migrate --force --no-interaction

    (If you trigger hands-off redeploys from a registry webhook without running the one-off command, set AUTO_MIGRATE="true" and AUTO_MIGRATE_LOCK="true" on the app service only; horizon and scheduler stay AUTO_MIGRATE="false".)

  2. Trigger Redeploy in Dokploy: Click Redeploy in the Dokploy Stack service.

  3. Start-First Rollout:

    • Docker Swarm starts the new app replica first.
    • The new replica syncs its hashed Vite assets additively into /app/storage/app/build-assets, warms caches, and boots FrankenPHP + Inertia SSR.
    • Swarm waits up to 60 seconds (start_period) for the health check endpoint /up to return HTTP 200.
  4. Route Traffic Without Interrupting Open Tabs:

    • Once healthy, Traefik routes incoming connections to the new container and drains the previous container (stop_grace_period: 30s).
    • Open portal tabs keep resolving their previous JS/CSS chunks from /app/storage/app/build-assets, show a non-blocking “Update ready” toast instead of forcing a 409 reload mid-form, and upgrade cleanly on the next cross-page navigation once no forms are dirty.
  5. Independent Worker Updates:

    • The horizon and scheduler services update in parallel without causing web request downtime.
    • Horizon workers finish active jobs before terminating (stop_grace_period: 30m).

GitHub Source Updates (Auto Deploy on Push to master)

Section titled “GitHub Source Updates (Auto Deploy on Push to master)”

When Dokploy builds directly from GitHub on every push to master:

  1. Zero-downtime build phase: Dokploy builds docker/Dockerfile.franken first without stopping the running app container.
  2. Locked automatic migrations before /up turns healthy: Because no operator runs a manual release command on a Git push, set AUTO_MIGRATE="true" and AUTO_MIGRATE_LOCK="true" on the web app service (and AUTO_MIGRATE="false" on horizon and scheduler). On container boot, docker/start-container runs php artisan app:migrate-locked, which acquires a blocking database advisory lock (PostgreSQL pg_advisory_lock / MySQL GET_LOCK / Redis lock) before running migrations—so concurrent replicas wait safely instead of racing, and FrankenPHP only binds port 8000 once the schema is current.
  3. Expand-and-contract discipline: Because the previous container keeps serving active traffic until the new container passes /up, commits pushed to master must keep schema changes backward-compatible with the currently running release (add nullable columns/tables first; drop or rename legacy columns in a subsequent push).
  4. Multiple pushes during working hours: Because RETAIN_PREVIOUS_BUILD_ASSETS="true" retains hashed chunks for 7 days and INERTIA_SOFT_VERSION_UPDATES="true" avoids abrupt 409 reloads, even repeated pushes to master during the day will not wipe unsaved portal forms.

Method 2: Standalone Application (GitHub Auto Deploy or Managed Databases)

Section titled “Method 2: Standalone Application (GitHub Auto Deploy or Managed Databases)”

Use standalone Dokploy Application services if you deploy directly from a GitHub repository (with Auto Deploy on push to master) or prefer Dokploy’s UI-managed databases:

  1. Create PostgreSQL:
    • Go to Databases → Create PostgreSQL.
    • Set Database name: koakademy, Username: koakademy.
  2. Create Redis:
    • Go to Databases → Create Redis.
  3. Deploy Gotenberg:
    • Create an Application service with image gotenberg/gotenberg:8. Expose port 3000 to internal network.
  4. Deploy the Web Application (app):
    • Create an Application service using either:
      • Provider → GitHub (branch master, Build Type Dockerfile, Dockerfile path docker/Dockerfile.franken, Auto Deploy enabled), or
      • Provider → Docker with image ghcr.io/yukazakiri/koakademy:latest-franken (or Docker Hub equivalent).
    • Set internal container port to 8000.
    • Mount persistent volume: Host /var/lib/dokploy/volumes/koakademy-storage -> Container /app/storage.
    • Set healthcheck path to /up.
    • In Advanced → Swarm Settings, set Update Config to order: start-first and failure_action: rollback, set stop_grace_period to 30s, and keep the /up healthcheck active.
    • Connect the environment variables pointing to PostgreSQL and Redis, and set:
      • HORIZON_IN_HTTP_CONTAINER="false"
      • APP_MAINTENANCE_DRIVER="cache" and APP_MAINTENANCE_STORE="redis"
      • RETAIN_PREVIOUS_BUILD_ASSETS="true" and INERTIA_SOFT_VERSION_UPDATES="true"
      • For GitHub Auto Deploy: AUTO_MIGRATE="true" and AUTO_MIGRATE_LOCK="true"
  5. Deploy Dedicated horizon and scheduler Applications:
    • Create two additional Application services pointing at the same GitHub repo / image, sharing the same /var/lib/dokploy/volumes/koakademy-storage -> /app/storage volume and database/Redis env vars:
      • horizon: CONTAINER_MODE="horizon", AUTO_MIGRATE="false", RUN_OPTIMIZE="false", RUN_SCOUT_SETTINGS="false", stop_grace_period: 30m.
      • scheduler: CONTAINER_MODE="scheduler", AUTO_MIGRATE="false", RUN_OPTIMIZE="false", RUN_SCOUT_SETTINGS="false", stop_grace_period: 30s.
    • Because all services share /app/storage, retained Vite build assets and soft browser updates work automatically on single-node Dokploy. (If scaling across multiple Swarm nodes, configure external S3/R2 storage and ASSET_URL.)

  1. Once the build completes and Traefik routes traffic, navigate to https://school.example.com/setup.
  2. Complete the initial registration wizard to set up your school and admin credentials.
  3. Check the application status at https://school.example.com/up.