Portainer Templates logo

Portainer Templates

Dify Dify

Stack

LLM Infrastructure

Dify - the LLM application platform: a visual builder for chatbots, agents, and workflows, with built-in RAG, model management, and observability.

Configuration

Type
Compose
Platform
linux
Env vars
DB_PASSWORD=''INNER_API_KEY=''PLUGIN_DAEMON_KEY=''QDRANT_API_KEY=''REDIS_AUTH=# openssl rand -hex 24SANDBOX_API_KEY=''SECRET_KEY=''
Source

Services

api

Configuration

Image
langgenius/dify-api:1.14.2
Volumes
/app/api/storage : appstorage
Env vars
SECRET_KEY=${SECRET_KEY}DB_USERNAME=postgresDB_PASSWORD=${DB_PASSWORD}DB_HOST=dbDB_PORT=5432DB_DATABASE=difyREDIS_HOST=redisREDIS_PORT=6379REDIS_PASSWORD=${REDIS_AUTH}CELERY_BROKER_URL=redis://:${REDIS_AUTH}@redis:6379/1VECTOR_STORE=qdrantQDRANT_URL=http://vectordb:6333QDRANT_API_KEY=${QDRANT_API_KEY}STORAGE_TYPE=opendalOPENDAL_SCHEME=fsOPENDAL_FS_ROOT=/app/api/storageCODE_EXECUTION_ENDPOINT=http://sandbox:8194CODE_EXECUTION_API_KEY=${SANDBOX_API_KEY}SSRF_PROXY_HTTP_URL=http://ssrf-proxy:3128SSRF_PROXY_HTTPS_URL=http://ssrf-proxy:3128PLUGIN_DAEMON_URL=http://plugin-daemon:5002PLUGIN_DAEMON_KEY=${PLUGIN_DAEMON_KEY}PLUGIN_DIFY_INNER_API_URL=http://api:5001PLUGIN_DIFY_INNER_API_KEY=${INNER_API_KEY}INNER_API_KEY_FOR_PLUGIN=${INNER_API_KEY}MIGRATION_ENABLED=trueMODE=api
Restart
unless-stopped

Image details

Pulls: 24.1M
User: langgenius
Created: May 08, 2023
Updated: 3 hours ago
Status: active

worker

Configuration

Image
langgenius/dify-api:1.14.2
Volumes
/app/api/storage : appstorage
Env vars
SECRET_KEY=${SECRET_KEY}DB_USERNAME=postgresDB_PASSWORD=${DB_PASSWORD}DB_HOST=dbDB_PORT=5432DB_DATABASE=difyREDIS_HOST=redisREDIS_PORT=6379REDIS_PASSWORD=${REDIS_AUTH}CELERY_BROKER_URL=redis://:${REDIS_AUTH}@redis:6379/1VECTOR_STORE=qdrantQDRANT_URL=http://vectordb:6333QDRANT_API_KEY=${QDRANT_API_KEY}STORAGE_TYPE=opendalOPENDAL_SCHEME=fsOPENDAL_FS_ROOT=/app/api/storageCODE_EXECUTION_ENDPOINT=http://sandbox:8194CODE_EXECUTION_API_KEY=${SANDBOX_API_KEY}SSRF_PROXY_HTTP_URL=http://ssrf-proxy:3128SSRF_PROXY_HTTPS_URL=http://ssrf-proxy:3128PLUGIN_DAEMON_URL=http://plugin-daemon:5002PLUGIN_DAEMON_KEY=${PLUGIN_DAEMON_KEY}PLUGIN_DIFY_INNER_API_URL=http://api:5001PLUGIN_DIFY_INNER_API_KEY=${INNER_API_KEY}INNER_API_KEY_FOR_PLUGIN=${INNER_API_KEY}MIGRATION_ENABLED=trueMODE=worker
Restart
unless-stopped

Image details

Pulls: 24.1M
User: langgenius
Created: May 08, 2023
Updated: 3 hours ago
Status: active

worker_beat

Configuration

Image
langgenius/dify-api:1.14.2
Env vars
SECRET_KEY=${SECRET_KEY}DB_USERNAME=postgresDB_PASSWORD=${DB_PASSWORD}DB_HOST=dbDB_PORT=5432DB_DATABASE=difyREDIS_HOST=redisREDIS_PORT=6379REDIS_PASSWORD=${REDIS_AUTH}CELERY_BROKER_URL=redis://:${REDIS_AUTH}@redis:6379/1VECTOR_STORE=qdrantQDRANT_URL=http://vectordb:6333QDRANT_API_KEY=${QDRANT_API_KEY}STORAGE_TYPE=opendalOPENDAL_SCHEME=fsOPENDAL_FS_ROOT=/app/api/storageCODE_EXECUTION_ENDPOINT=http://sandbox:8194CODE_EXECUTION_API_KEY=${SANDBOX_API_KEY}SSRF_PROXY_HTTP_URL=http://ssrf-proxy:3128SSRF_PROXY_HTTPS_URL=http://ssrf-proxy:3128PLUGIN_DAEMON_URL=http://plugin-daemon:5002PLUGIN_DAEMON_KEY=${PLUGIN_DAEMON_KEY}PLUGIN_DIFY_INNER_API_URL=http://api:5001PLUGIN_DIFY_INNER_API_KEY=${INNER_API_KEY}INNER_API_KEY_FOR_PLUGIN=${INNER_API_KEY}MIGRATION_ENABLED=trueMODE=beat
Restart
unless-stopped

Image details

Pulls: 24.1M
User: langgenius
Created: May 08, 2023
Updated: 3 hours ago
Status: active

web

Configuration

Image
langgenius/dify-web:1.14.2
Env vars
CONSOLE_API_URL=APP_API_URL=
Restart
unless-stopped

Image details

Pulls: 15.9M
User: langgenius
Created: May 08, 2023
Updated: 3 hours ago
Status: active

plugin_daemon

Configuration

Image
langgenius/dify-plugin-daemon:0.4.1-local
Volumes
/app/storage : pluginstorage
Env vars
DB_USERNAME=postgresDB_PASSWORD=${DB_PASSWORD}DB_HOST=dbDB_PORT=5432DB_DATABASE=dify_pluginREDIS_HOST=redisREDIS_PORT=6379REDIS_PASSWORD=${REDIS_AUTH}SERVER_PORT=5002SERVER_KEY=${PLUGIN_DAEMON_KEY}DIFY_INNER_API_URL=http://api:5001DIFY_INNER_API_KEY=${INNER_API_KEY}PLUGIN_WORKING_PATH=/app/storage/cwdPLUGIN_REMOTE_INSTALLING_HOST=0.0.0.0PLUGIN_REMOTE_INSTALLING_PORT=5003PLUGIN_REMOTE_INSTALLING_ENABLED=true
Restart
unless-stopped

Image details

Pulls: 9.1M
User: yeuoly
Created: Oct 17, 2024
Updated: 1 day ago
Status: active

sandbox

Configuration

Image
langgenius/dify-sandbox:0.2.12
Env vars
API_KEY=${SANDBOX_API_KEY}GIN_MODE=releaseWORKER_TIMEOUT=15ENABLE_NETWORK=trueHTTP_PROXY=http://ssrf-proxy:3128HTTPS_PROXY=http://ssrf-proxy:3128
Restart
unless-stopped

Image details

Pulls: 10.5M
User: yeuoly
Created: Mar 11, 2024
Updated: 2 months ago
Status: active

ssrf_proxy

Configuration

Restart
unless-stopped
Build
./ssrf-proxy

entry

Configuration

Ports
5000:5000
Restart
unless-stopped
Build
./entry

redis

Configuration

Env vars
REDIS_AUTH=${REDIS_AUTH}
Restart
unless-stopped
Build
./redis

db

Configuration

Volumes
/var/lib/postgresql/data : dbdata
Env vars
POSTGRES_PASSWORD=${DB_PASSWORD}POSTGRES_DB=difyPGDATA=/var/lib/postgresql/data/pgdata
Restart
unless-stopped
Build
./db

vectordb

Configuration

Image
qdrant/qdrant:v1.18.3
Volumes
/qdrant/storage : qdrantdata
Env vars
QDRANT__SERVICE__API_KEY=${QDRANT_API_KEY}
Restart
unless-stopped

Image details

Pulls: 47.1M
User: generall
Created: Feb 03, 2022
Updated: 37 minutes ago
Status: active

Standalone Install

Select an install method, to see config/commands for deploying Dify

Installation method

Install on Portainer

Import all app templates into your Portainer instance, for easy 1-click deploys

  1. Ensure both Docker and Portainer are installed, and up-to-date
  2. Log into your Portainer web UI
  3. Under Settings → App Templates, paste the below URL
  4. Head to Home → App Templates, and the list of apps will show up
  5. Select Dify, fill in any config options, and hit Deploy

Template Import URL

https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json
Show Me demo
Original stackfile

The compose file this template deploys, straight from its repo:

name: dify

x-api-env: &api-env
  SECRET_KEY: ${SECRET_KEY}
  DB_USERNAME: postgres
  DB_PASSWORD: ${DB_PASSWORD}
  DB_HOST: db
  DB_PORT: "5432"
  DB_DATABASE: dify
  REDIS_HOST: redis
  REDIS_PORT: "6379"
  REDIS_PASSWORD: ${REDIS_AUTH}
  CELERY_BROKER_URL: redis://:${REDIS_AUTH}@redis:6379/1
  VECTOR_STORE: qdrant
  QDRANT_URL: http://vectordb:6333
  QDRANT_API_KEY: ${QDRANT_API_KEY}
  STORAGE_TYPE: opendal
  OPENDAL_SCHEME: fs
  OPENDAL_FS_ROOT: /app/api/storage
  CODE_EXECUTION_ENDPOINT: http://sandbox:8194
  CODE_EXECUTION_API_KEY: ${SANDBOX_API_KEY}
  SSRF_PROXY_HTTP_URL: http://ssrf-proxy:3128
  SSRF_PROXY_HTTPS_URL: http://ssrf-proxy:3128
  PLUGIN_DAEMON_URL: http://plugin-daemon:5002
  PLUGIN_DAEMON_KEY: ${PLUGIN_DAEMON_KEY}
  PLUGIN_DIFY_INNER_API_URL: http://api:5001
  PLUGIN_DIFY_INNER_API_KEY: ${INNER_API_KEY}
  INNER_API_KEY_FOR_PLUGIN: ${INNER_API_KEY}
  MIGRATION_ENABLED: "true"

services:
  api:
    image: langgenius/dify-api:1.14.2
    restart: unless-stopped
    environment:
      <<: *api-env
      MODE: api
    volumes:
      - appstorage:/app/api/storage
    depends_on: [db, redis, vectordb]

  worker:
    image: langgenius/dify-api:1.14.2
    restart: unless-stopped
    environment:
      <<: *api-env
      MODE: worker
    volumes:
      - appstorage:/app/api/storage
    depends_on: [db, redis, vectordb]

  worker_beat:
    image: langgenius/dify-api:1.14.2
    restart: unless-stopped
    environment:
      <<: *api-env
      MODE: beat
    depends_on: [db, redis]

  web:
    image: langgenius/dify-web:1.14.2
    restart: unless-stopped
    environment:
      CONSOLE_API_URL: ""
      APP_API_URL: ""

  plugin_daemon:
    image: langgenius/dify-plugin-daemon:0.4.1-local
    restart: unless-stopped
    environment:
      DB_USERNAME: postgres
      DB_PASSWORD: ${DB_PASSWORD}
      DB_HOST: db
      DB_PORT: "5432"
      DB_DATABASE: dify_plugin
      REDIS_HOST: redis
      REDIS_PORT: "6379"
      REDIS_PASSWORD: ${REDIS_AUTH}
      SERVER_PORT: "5002"
      SERVER_KEY: ${PLUGIN_DAEMON_KEY}
      DIFY_INNER_API_URL: http://api:5001
      DIFY_INNER_API_KEY: ${INNER_API_KEY}
      PLUGIN_WORKING_PATH: /app/storage/cwd
      PLUGIN_REMOTE_INSTALLING_HOST: "0.0.0.0"
      PLUGIN_REMOTE_INSTALLING_PORT: "5003"
      PLUGIN_REMOTE_INSTALLING_ENABLED: "true"
    volumes:
      - pluginstorage:/app/storage
    depends_on: [db, redis]

  sandbox:
    image: langgenius/dify-sandbox:0.2.12
    restart: unless-stopped
    environment:
      API_KEY: ${SANDBOX_API_KEY}
      GIN_MODE: release
      WORKER_TIMEOUT: "15"
      ENABLE_NETWORK: "true"
      HTTP_PROXY: http://ssrf-proxy:3128
      HTTPS_PROXY: http://ssrf-proxy:3128

  ssrf_proxy:
    build: ./ssrf-proxy
    restart: unless-stopped

  entry:
    build: ./entry
    restart: unless-stopped
    ports:
      - "5000:5000"
    depends_on: [api, web]

  redis:
    build: ./redis
    restart: unless-stopped
    environment:
      REDIS_AUTH: ${REDIS_AUTH}

  db:
    build: ./db
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: dify
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - dbdata:/var/lib/postgresql/data

  vectordb:
    image: qdrant/qdrant:v1.18.3
    restart: unless-stopped
    environment:
      QDRANT__SERVICE__API_KEY: ${QDRANT_API_KEY}
    volumes:
      - qdrantdata:/qdrant/storage

volumes:
  appstorage:
  pluginstorage:
  dbdata:
  qdrantdata:

Or deploy it directly from the source:

git clone https://github.com/deployable-sh/stacks
cd stacks
docker compose -f dify/compose.yaml up -d

More install options in our documentation.

Container Documentation

api Documentation

The Dify.AI Backend Docker Image.

worker Documentation

The Dify.AI Backend Docker Image.

worker_beat Documentation

The Dify.AI Backend Docker Image.

web Documentation

The Dify.AI Frontend Docker Image.

sandbox Documentation

vectordb Documentation

Qdrant - vector similarity search engine with extended filtering support

Serve Dify on your own domain behind Caddy, Nginx or Traefik. Fill in your domain and copy the result. It's a starting point, some apps need their own base URL or extra headers set too.

Proxying dify.example.com to http://entry:5000

Add this to your Caddyfile

dify.example.com {
	reverse_proxy http://entry:5000
}

Check the logs first

Nine times out of ten the logs tell you exactly what went wrong.

  • In Portainer, go to Containers, click the container, then Logs. Or run docker logs <container>
  • Exit codes help too: 137 means killed, usually out of memory. 126 or 127 means the command inside the image is broken.

Port already in use

If deployment fails with "Bind for 0.0.0.0:5000 failed: port is already allocated", something else on your server is using that port.

  • Find what's using it: sudo ss -tlnp | grep :5000
  • Stop the other service, or pick a different host port. In 5000:5000 only the left number is yours to change, the right one belongs to the app.

Running but the page won't load

The container is up but nothing appears in your browser.

  • Use your server's real IP: http://your-server-ip:5000. The 0.0.0.0 link Portainer shows isn't a real address.
  • Give it a minute after first deploy, dify can take a while to initialise.
  • Make sure your firewall allows the port, e.g. sudo ufw allow 5000

Image won't pull

Test the pull directly on the host: docker pull langgenius/dify-api:1.14.2

  • "manifest unknown" means the tag no longer exists.
  • "toomanyrequests" is the Docker Hub rate limit. Log in with docker login to raise it.
  • "no space left on device" means a full disk. Reclaim space with docker system prune

"exec format error"

This means the image was built for a different CPU architecture than your server.

  • Check yours with uname -m: x86_64 is amd64, aarch64 is arm64. Raspberry Pi and other ARM boards are the usual culprits.

Container keeps restarting

The unless-stopped restart policy relaunches the app after every crash, so the real error can scroll past.

  • Check the logs right after a restart, the last few lines before it died are the useful ones.
  • Get the exit code with docker inspect <container> --format '{{.State.ExitCode}}'
  • Still stuck? Redeploy once with the restart policy set to no so the failure stays visible.

Required settings are blank

CONSOLE_API_URL, APP_API_URL have no default value, and dify may crash or misbehave if left empty.

  • Fill them in on the deploy screen before hitting deploy.

Stack won't deploy

Compose stacks fail fast on small mistakes, and Portainer shows the reason just above the editor.

  • YAML only accepts spaces for indentation, a single tab breaks the whole file.

Raise an issue

Found something which isn't working as it should? Here's how to report it.

A Compose stack

Dify is a Compose stack, a set of containers (11 of them) defined in one file and brought up together by Portainer, then started and stopped as a single app.

The services

This stack is built from 11 containers that run side by side. Here's each one, with the image it runs and anything it waits for first:

  • api runs langgenius/dify-api:1.14.2, starts after db, redis, vectordb
  • worker runs langgenius/dify-api:1.14.2, starts after db, redis, vectordb
  • worker_beat runs langgenius/dify-api:1.14.2, starts after db, redis
  • web runs langgenius/dify-web:1.14.2
  • plugin_daemon runs langgenius/dify-plugin-daemon:0.4.1-local, starts after db, redis
  • sandbox runs langgenius/dify-sandbox:0.2.12
  • ssrf_proxy
  • entry, starts after api, web
  • redis
  • db
  • vectordb runs qdrant/qdrant:v1.18.3

Ports

A port is the door the app answers on. A mapping like 5000:5000 means it's reachable on port 5000 of your server, where the left number is yours to change and the right one belongs to the app. It opens:

  • 5000:5000

Volumes

A volume is where Dify keeps its files so they survive an update or a restart. Without one, anything it saves would sit inside the container and vanish the moment it's recreated. This template mounts:

  • /app/api/storage kept in the appstorage volume Docker manages
  • /app/storage kept in the pluginstorage volume Docker manages
  • /var/lib/postgresql/data kept in the dbdata volume Docker manages
  • /qdrant/storage kept in the qdrantdata volume Docker manages

Environment variables

Environment variables are the settings you hand over when you deploy, things like a password or a timezone. Dify takes 48 of them, and 2 need a value before it'll start properly:

  • SECRET_KEY, pulled from your own environment
  • DB_USERNAME, defaults to postgres
  • DB_PASSWORD, pulled from your own environment
  • DB_HOST, defaults to db
  • DB_PORT, defaults to 5432
  • DB_DATABASE, defaults to dify_plugin
  • REDIS_HOST, defaults to redis
  • REDIS_PORT, defaults to 6379
  • REDIS_PASSWORD, pulled from your own environment
  • CELERY_BROKER_URL, defaults to redis://:REDIS_AUTH@redis:6379/1
  • VECTOR_STORE, defaults to qdrant
  • QDRANT_URL, defaults to http://vectordb:6333
  • QDRANT_API_KEY, pulled from your own environment
  • STORAGE_TYPE, defaults to opendal
  • OPENDAL_SCHEME, defaults to fs
  • OPENDAL_FS_ROOT, defaults to /app/api/storage
  • CODE_EXECUTION_ENDPOINT, defaults to http://sandbox:8194
  • CODE_EXECUTION_API_KEY, pulled from your own environment
  • SSRF_PROXY_HTTP_URL, defaults to http://ssrf-proxy:3128
  • SSRF_PROXY_HTTPS_URL, defaults to http://ssrf-proxy:3128
  • PLUGIN_DAEMON_URL, defaults to http://plugin-daemon:5002
  • PLUGIN_DAEMON_KEY, pulled from your own environment
  • PLUGIN_DIFY_INNER_API_URL, defaults to http://api:5001
  • PLUGIN_DIFY_INNER_API_KEY, pulled from your own environment
  • INNER_API_KEY_FOR_PLUGIN, pulled from your own environment
  • MIGRATION_ENABLED, defaults to true
  • MODE, defaults to beat
  • CONSOLE_API_URL, needs a value
  • APP_API_URL, needs a value
  • SERVER_PORT, defaults to 5002
  • SERVER_KEY, pulled from your own environment
  • DIFY_INNER_API_URL, defaults to http://api:5001
  • DIFY_INNER_API_KEY, pulled from your own environment
  • PLUGIN_WORKING_PATH, defaults to /app/storage/cwd
  • PLUGIN_REMOTE_INSTALLING_HOST, defaults to 0.0.0.0
  • PLUGIN_REMOTE_INSTALLING_PORT, defaults to 5003
  • PLUGIN_REMOTE_INSTALLING_ENABLED, defaults to true
  • API_KEY, pulled from your own environment
  • GIN_MODE, defaults to release
  • WORKER_TIMEOUT, defaults to 15
  • ENABLE_NETWORK, defaults to true
  • HTTP_PROXY, defaults to http://ssrf-proxy:3128
  • HTTPS_PROXY, defaults to http://ssrf-proxy:3128
  • REDIS_AUTH, pulled from your own environment
  • POSTGRES_PASSWORD, pulled from your own environment
  • POSTGRES_DB, defaults to dify
  • PGDATA, defaults to /var/lib/postgresql/data/pgdata
  • QDRANT__SERVICE__API_KEY, pulled from your own environment

Restart policy

The restart policy here is unless-stopped, so Docker restarts Dify after a crash or reboot, but leaves it off when you stop it on purpose. You can change this on the deploy screen. The choices are no (never restart), on-failure (only after a crash), unless-stopped (restart unless you stop it), and always (bring it back no matter what).

Networking

Portainer puts these services on one shared private network, so they can find each other by name (like api) while only the ports above are open to you.

Platform

The platform is linux, the kind of system the container is built to run on. Docker and Portainer handle this on a normal Linux server.

Portainer app templates

Zooming out, this whole page comes from a Portainer app template: a short recipe telling Portainer how to set Dify up. Add the template list to Portainer once, then deploying Dify is a click rather than a wall of config.