# Self-host Dify. In one sentence.

> Self-host Dify without a VPS or docker compose: one sentence in Claude Code, Codex or Cursor runs Dify on Agent Lab with PostgreSQL (pgvector) and Redis.

Web page: https://agentlab.cresclab.com/en/deploy/dify  
繁體中文 (Markdown): https://agentlab.cresclab.com/deploy/dify.md

Self-host Dify · Agent Lab Deploy

Skip the ten-service docker compose: say one sentence and Agent Lab runs Dify as apps on PostgreSQL (pgvector) and Redis.

[Set up Dify](https://app.agentlab.cresclab.com/?lang=en&intent=deploy) [See the architecture](https://agentlab.cresclab.com/en/deploy/dify#recipe)

A Claude Code conversation: the user asks for Dify from this page; the agent creates four apps, a PostgreSQL and a Redis and connects them, generates the secret, and returns Dify's URL.

Why self-host

## Dify Cloud caps by plan. Self-hosted follows your usage.

Self-hosted, quotas, knowledge size and seats follow your resources.

### No docker compose to babysit

API, worker, web and plugin daemon are separate apps that restart independently.

### pgvector as the vector store

Vectors live in the same PostgreSQL. No separate Weaviate.

### Your own model keys

Model keys stay in your database; the platform generates SECRET_KEY.

Choosing

## Dify Cloud vs a VPS vs Agent Lab

Three ways to run Dify compared

| What matters to you | Agent Lab Deploy | Dify Cloud | Your own VPS |
| --- | --- | --- | --- |
| Quotas | Your resources | Capped per plan | Your server |
| Who runs it | The platform | Dify | You |
| Vector store | PostgreSQL pgvector | Managed by Dify | Weaviate, yours to run |
| Where the data lives | Your Agent Lab organization | Dify's cloud | Your server |
| Setup | One sentence to an AI tool | Sign up | docker compose, ten services |

How

## Connect → one sentence → storage keys → open Dify

Starts on Pro.

1. ### Connect Agent Lab
   One MCP line in your AI tool, one sign-in.
2. ### Say one sentence
   The agent creates four apps, PostgreSQL (pgvector) and Redis, all connected.
3. ### Set file storage
   Put your S3-compatible bucket keys in the console's project secrets.
4. ### Open Dify
   Open dify-web's URL, set the admin, add model keys.

Architecture

## Four apps, one database, one Redis

api serves, worker indexes, web is the UI, plugin runs plugins; add a sandbox for code nodes.

Dockerfile

### Dockerfile

```
# 一個 Dify 由幾個 App 組成，每個一份 Dockerfile
# One Dify is several apps, one Dockerfile each

# dify-api
FROM langgenius/dify-api:latest
ENV MODE=api \
    DB_TYPE=postgresql \
    VECTOR_STORE=pgvector \
    STORAGE_TYPE=s3
EXPOSE 5001

# dify-worker:  same image, ENV MODE=worker
# dify-web:     FROM langgenius/dify-web:latest   (EXPOSE 3000)
# dify-plugin:  FROM langgenius/dify-plugin-daemon:latest-local
```

- `DB_HOST / DB_PORT / DB_DATABASE / DB_USERNAME / DB_PASSWORD` written by databases_connect_app; needs pgvector
- `REDIS_HOST / REDIS_PORT / REDIS_PASSWORD` written by caches_binding_connect
- `SECRET_KEY` from sites_secrets_generate, shared by all four
- `S3_BUCKET_NAME / S3_ACCESS_KEY / S3_SECRET_KEY` upload storage; set as console secrets

PROMPT

### Say this to your AI tool

```
Read https://app.agentlab.cresclab.com/agent/deploy.md and deploy Dify to Agent Lab following agentlab.cresclab.com/en/deploy/dify: create the dify-api, dify-worker, dify-web and dify-plugin apps; create and connect a PostgreSQL (with pgvector) and a Redis; generate SECRET_KEY on the platform; store files in my S3 bucket and tell me where in the console to enter its keys. Give me Dify's URL when it's up.
```

FAQ

## Before you self-host Dify

**How much does it cost to self-host Dify?**

It starts on Pro: US$29 a month before tax with US$14 of monthly usage credit that apps and databases draw on. Use an L database or larger.

**Self-hosted Dify vs Dify Cloud?**

Self-hosted, quotas follow your resources and data and keys stay in your organization, with your own settings and plugins; Dify Cloud is managed by Dify with per-plan caps.

**Do I have to use docker compose for Dify?**

The official example is docker compose, but every Dify service is its own image; on Agent Lab each is an app (dify-api, dify-worker, dify-web, dify-plugin) that builds and restarts on its own.

**Which vector database should Dify use?**

PostgreSQL's pgvector: set VECTOR_STORE to pgvector. No separate Weaviate or Qdrant, one backup.

**Do I need a VPS to host Dify?**

No. On Agent Lab each Dify service runs as an app with PostgreSQL (pgvector) and Redis, and the platform runs them; a VPS also works, but you run docker compose and its ten services yourself.

**Can I use Claude, GPT or Gemini?**

Yes. Enter your API keys under Settings › Model providers; they are stored encrypted in your database.
