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.
Choosing Your Dokploy Update Source
Section titled “Choosing Your Dokploy Update Source”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) |
Deployment Strategies
Section titled “Deployment Strategies”You can deploy KoAkademy in Dokploy using either:
- Zero-Downtime Docker Stack (Recommended for Docker Hub / GHCR Images): Deploys decoupled services (
appfor HTTP,horizonfor background queues,schedulerfor cron) with health-gatedstart-firstupdates, automated rollbacks, and tuned resource caps. - 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-firstenabled.
Method 1: Zero-Downtime Compose Stack Deployment (Recommended)
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
healthcheckscript probes/health(and supervisor processes). - VIP Routing Gate: Dokploy and Traefik keep routing user traffic to the old container until the new container reports
healthyover 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 newappcontainer copies its hashed/app/public/build/assets/*files additively into the sharedapp-storagevolume (/app/storage/app/build-assets) while keepingmanifest.jsoncontainer-local. Combined withINERTIA_SOFT_VERSION_UPDATES="true", active portal tabs never hit chunk404s during overlapping rollouts and receive a non-blocking “Update ready” prompt instead of an abrupt409hard reload mid-form.
Step 1: Create a Project in Dokploy
Section titled “Step 1: Create a Project in Dokploy”- Navigate to your Dokploy dashboard.
- Click Create Project and name it
koakademy. - Inside the project, click Create Service, select Compose, and choose Stack as the Compose Type.
Step 2: Configure Compose Stack
Section titled “Step 2: Configure Compose Stack”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: trueStep 3: Configure Environment Variables
Section titled “Step 3: Configure Environment Variables”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
# DatabaseDB_CONNECTION="pgsql"DB_HOST="pgsql"DB_PORT="5432"DB_DATABASE="koakademy"DB_USERNAME="koakademy"DB_PASSWORD="StrongDatabasePasswordHere"
# Redis Cache & QueuesCACHE_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 & PerformanceOCTANE_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 HardeningAPP_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 & StorageGOTENBERG_URL="http://gotenberg:3000"LARAVEL_PDF_DRIVER="gotenberg"LARAVEL_PDF_PRODUCTION_DRIVER="gotenberg"FILESYSTEM_DISK="public"Step 4: Domain & SSL Routing
Section titled “Step 4: Domain & SSL Routing”- In Dokploy’s Domains section, add your domain:
school.example.com. - Select service:
app, container port:8000. - Enable HTTPS / SSL Certificate via Let’s Encrypt or Cloudflare.
- 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):
-
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 thepgsqlservice.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"andAUTO_MIGRATE_LOCK="true"on theappservice only;horizonandschedulerstayAUTO_MIGRATE="false".) -
Trigger Redeploy in Dokploy: Click Redeploy in the Dokploy Stack service.
-
Start-First Rollout:
- Docker Swarm starts the new
appreplica 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/upto return HTTP200.
- Docker Swarm starts the new
-
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 a409reload mid-form, and upgrade cleanly on the next cross-page navigation once no forms are dirty.
- Once healthy, Traefik routes incoming connections to the new container and drains the previous container (
-
Independent Worker Updates:
- The
horizonandschedulerservices update in parallel without causing web request downtime. - Horizon workers finish active jobs before terminating (
stop_grace_period: 30m).
- The
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:
- Zero-downtime build phase: Dokploy builds
docker/Dockerfile.frankenfirst without stopping the runningappcontainer. - Locked automatic migrations before
/upturns healthy: Because no operator runs a manual release command on a Git push, setAUTO_MIGRATE="true"andAUTO_MIGRATE_LOCK="true"on the webappservice (andAUTO_MIGRATE="false"onhorizonandscheduler). On container boot,docker/start-containerrunsphp artisan app:migrate-locked, which acquires a blocking database advisory lock (PostgreSQLpg_advisory_lock/ MySQLGET_LOCK/ Redis lock) before running migrations—so concurrent replicas wait safely instead of racing, and FrankenPHP only binds port8000once the schema is current. - Expand-and-contract discipline: Because the previous container keeps serving active traffic until the new container passes
/up, commits pushed tomastermust keep schema changes backward-compatible with the currently running release (add nullable columns/tables first; drop or rename legacy columns in a subsequent push). - Multiple pushes during working hours: Because
RETAIN_PREVIOUS_BUILD_ASSETS="true"retains hashed chunks for 7 days andINERTIA_SOFT_VERSION_UPDATES="true"avoids abrupt409reloads, even repeated pushes tomasterduring 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:
- Create PostgreSQL:
- Go to Databases → Create PostgreSQL.
- Set Database name:
koakademy, Username:koakademy.
- Create Redis:
- Go to Databases → Create Redis.
- Deploy Gotenberg:
- Create an Application service with image
gotenberg/gotenberg:8. Expose port3000to internal network.
- Create an Application service with image
- Deploy the Web Application (
app):- Create an Application service using either:
- Provider → GitHub (branch
master, Build Type Dockerfile, Dockerfile pathdocker/Dockerfile.franken, Auto Deploy enabled), or - Provider → Docker with image
ghcr.io/yukazakiri/koakademy:latest-franken(or Docker Hub equivalent).
- Provider → GitHub (branch
- 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-firstandfailure_action: rollback, setstop_grace_periodto30s, and keep the/uphealthcheck active. - Connect the environment variables pointing to PostgreSQL and Redis, and set:
HORIZON_IN_HTTP_CONTAINER="false"APP_MAINTENANCE_DRIVER="cache"andAPP_MAINTENANCE_STORE="redis"RETAIN_PREVIOUS_BUILD_ASSETS="true"andINERTIA_SOFT_VERSION_UPDATES="true"- For GitHub Auto Deploy:
AUTO_MIGRATE="true"andAUTO_MIGRATE_LOCK="true"
- Create an Application service using either:
- Deploy Dedicated
horizonandschedulerApplications:- Create two additional Application services pointing at the same GitHub repo / image, sharing the same
/var/lib/dokploy/volumes/koakademy-storage->/app/storagevolume 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 andASSET_URL.)
- Create two additional Application services pointing at the same GitHub repo / image, sharing the same
Post-Installation Verification
Section titled “Post-Installation Verification”- Once the build completes and Traefik routes traffic, navigate to
https://school.example.com/setup. - Complete the initial registration wizard to set up your school and admin credentials.
- Check the application status at
https://school.example.com/up.
