Deploy Dify · Quick Start

Open-source LLM app and agent platform with workflows, RAG and plugins

Deploy Dify · Quick Start

/home/dify

Just deployed

/data

Just deployed

Just deployed

Just deployed

/var/lib/postgresql/data

Just deployed

Just deployed

Just deployed

Just deployed

/app/storage

dify-files

Bucket

Just deployed

Deploy and Host Dify on Railway

Dify is an open-source platform for building LLM apps: chatbots, agents, RAG over your own documents, and visual workflows, with a published API for each app. This template runs the full self-hosted stack from Dify's official docker-compose.yaml on Railway. It uses the official images, closes public sign-up, creates your admin account on first start and keeps everything on the private network except one HTTPS domain.

About Hosting Dify

  • The complete upstream stack. API, Celery worker, Celery beat, web console, code sandbox, plugin daemon, agent backend, agent sandbox and SSRF proxy. These are the same services and settings as upstream docker/docker-compose.yaml, with a small Caddy router in place of nginx using the same routes.
  • One public domain. The router is the only service with a domain. The console, /console/api, /api, /v1 (Service API), /files, /mcp, /triggers, /socket.io and plugin endpoints (/e/...) all share one origin, so Dify's cookie login works without cross-site settings. Every other service talks over *.railway.internal.
  • No default login. The admin account is created from ADMIN_EMAIL with a generated password. /install is locked by a generated INIT_PASSWORD, and public sign-up and workspace creation are off.
  • All secrets generated. These include SECRET_KEY, the plugin daemon key, the inner API key, the sandbox key, the agent tokens and the Postgres and Redis passwords. They are stored as variables, so they survive redeploys.
  • Outbound traffic is filtered. HTTP requests from workflows, the code sandbox and the agent sandbox go through Squid, which blocks private, loopback, link-local and cloud-metadata addresses. Plugin signature checks are on, so only marketplace-signed plugins install.
  • Durable storage.
    • Postgres with pgvector holds metadata, knowledge-base vectors and the plugin database, on a volume.
    • Redis runs on a volume.
    • Uploads and tenant encryption keys go to a Railway bucket (S3).
    • Installed plugins and the agent sandbox home have their own volumes.
  • Tracks upstream. Images use :latest (the plugin daemon uses latest-local), and database migrations run automatically when the API starts.

Getting started

  1. Enter ADMIN_EMAIL (the only input) and deploy. The first start takes a few minutes while the API runs database migrations.
  2. Open the API service, then Variables, and copy ADMIN_PASSWORD.
  3. Open the Dify service's public URL and sign in with ADMIN_EMAIL and ADMIN_PASSWORD. Change the password under Settings → Account.
  4. Go to Settings → Model Provider, install a provider plugin from the marketplace (OpenAI, Anthropic, Gemini, Ollama, …) and add your API key.
  5. In Studio, create an app (chatbot, agent or workflow), test it, publish it, and call it through the Service API at https://YOUR_DOMAIN/v1 with an app API key.
  6. If you left ADMIN_EMAIL empty, open https://YOUR_DOMAIN/install, enter INIT_PASSWORD from the API service's variables and create the admin there.

Common Use Cases

  • Chat assistants that answer from your own documents (knowledge bases with pgvector retrieval).
  • Workflow automation that mixes LLM steps, Python and JavaScript code nodes, HTTP requests and tools.
  • Agents that call marketplace plugins and tools, or your own APIs.
  • A backend for LLM features in your product, using each app's REST API and API keys.
  • Comparing model providers and prompts in one place before shipping.

Dependencies for Dify Hosting

  • PostgreSQL with the pgvector extension (metadata, vectors and the plugin database)
  • Redis (cache, locks and the Celery broker)
  • S3-compatible object storage (a Railway bucket)

Deployment Dependencies

Implementation Details

ServiceImageRole
Difycaddy:latestPublic router on port 8080, with the same routes as upstream nginx. Healthcheck /healthz
APIlanggenius/dify-api:latestConsole and Service API. Runs migrations and seeds the admin. Serves Socket.IO for collaboration. Healthcheck /health
Workerlanggenius/dify-api:latestCelery worker for indexing, workflows, mail and cleanup
Worker-Beatlanggenius/dify-api:latestCelery beat scheduler
Weblanggenius/dify-web:latestNext.js console. Healthcheck /signin
Plugin-Daemonlanggenius/dify-plugin-daemon:latest-localInstalls and runs plugins. Volume /app/storage. Healthcheck /health/check
Sandboxlanggenius/dify-sandbox:latestRuns code nodes. Healthcheck /health
SSRF-Proxyubuntu/squid:latestOutbound proxy that blocks private and metadata addresses
Agent-Backendlanggenius/dify-agent-backend:latestAgent v2 runtime. Healthcheck /docs
Agent-Sandboxlanggenius/dify-agent-local-sandbox:latestShell sandbox for agent tools. Volume /home/dify. Healthcheck /healthz
Postgrespgvector/pgvector:pg18Databases dify and dify_plugin, with pgvector. Volume /var/lib/postgresql/data
Redisredis:8.2Cache and broker. Volume /data
dify-files (bucket)Railway bucketUploads, generated files and tenant keys
VariableServicePurpose
ADMIN_EMAILAPIThe only input. The admin account created on first start. Leave empty to use /install instead
ADMIN_PASSWORDAPIGenerated admin password, used only when the admin is created
INIT_PASSWORDAPIGenerated password that guards /install
SECRET_KEYAPISigns sessions and encrypts stored credentials. Never change it after the first deploy
DIFY_PUBLIC_HOSTDifyThe public host name. Every service builds its URLs from it
SERVER_KEYPlugin-DaemonKey the API and agent backend use to call the plugin daemon
INNER_API_KEY_FOR_PLUGINAPIKey the plugin daemon and agent backend use to call back into the API
API_KEYSandboxKey for the code sandbox
DIFY_AGENT_API_TOKEN, DIFY_AGENT_SERVER_SECRET_KEYAgent-BackendAgent backend token and stub signing key
SHELLCTL_AUTH_TOKENAgent-SandboxToken for the agent sandbox
SQUID_CONF, CADDYFILESSRF-Proxy, DifyProxy and router configs, written to disk at start

Custom domain: add the domain to the Dify service (target port 8080), set DIFY_PUBLIC_HOST on that service to the new host name, then redeploy API, Worker and Web so they pick up the new URL.

Email: password reset, invitations and email login need a mail provider. Set MAIL_TYPE (resend or smtp) and its variables on API and Worker, as described in Dify's environment docs.

Upgrades: the services pull :latest on every deploy. To upgrade, redeploy API first, because it runs migrations, then the other dify-* services. Back up Postgres before a major Dify release. To pin a version, change the image tag on API, Worker, Worker-Beat, Web, Sandbox and the agent services to the same release (for example 1.19.0). Pin the plugin daemon to its matching -local tag. Keep SECRET_KEY and the bucket. Without them, stored model credentials can't be decrypted.

Why Deploy Dify on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Dify on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
Weaviate
Vector database with hybrid search and an API key-protected API

GitHub Locker
1
View Template
Möbius Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

bento
1