运维与配置(2/2)

How to move a self-hosted Weaviate server across minor versions without losing vector data

Dify 1.17.1 updates its bundled Weaviate server from 1.27.0 to 1.39.2, and an existing Weaviate data volume cannot cross that gap in one step. This procedure covers Dify's default, single-node Docker Compose deployment. Fresh deployments start with the new version on an empty volume and do not need this procedure.

Weaviate neither tests nor supports skipping minor versions, and any release may carry an on-disk migration that expects the previous version to have run at least once.

The supported path is to step through every minor release in order, landing on the latest patch of each. Below is that ladder, along with the two operational details that most often go wrong along the way.

Back up your Weaviate volume before you start. An upgrade that goes wrong partway through the ladder is only recoverable if you have a snapshot to return to.

Check Your Current Version

From the Dify repository root, enter the docker directory and keep the shell there. The default docker-compose.yaml does not publish a host port for Weaviate, so run the check inside the Compose network rather than against localhost on your host:

cd docker
docker compose exec -T weaviate \
  wget -qO- --header="Authorization: Bearer <WEAVIATE_API_KEY>" \
  http://localhost:8080/v1/meta \
  | python3 -c "import sys, json; print(json.load(sys.stdin)['version'])"

The localhost in the URL is the Weaviate container's own loopback, not your host's. The Weaviate image has no curl and no Python, so the request uses busybox wget and the JSON is formatted by Python on your host.

If this reports 1.39.2, you are done. Continue below from 1.27.0; if it reports an intermediate version in the ladder, resume with the next rung. For a version earlier than 1.27.0, follow the Weaviate v4 migration guide first.

Back Up Your Data

For a Docker deployment, the simplest backup is an offline copy of the volume. First stop Dify's request and worker services, and keep them stopped until the final rung passes:

If your docker-compose.yaml does not define api_websocket, omit it from the command below.

docker compose stop -t 120 nginx api api_websocket worker worker_beat || exit 1

Run Verify Each Step once to record the starting object count and confirm synchronization. Then stop Weaviate and copy the volume:

docker compose stop -t -1 weaviate || exit 1
sudo cp -a ./volumes/weaviate ./volumes/weaviate_backup_$(date +%Y%m%d) || exit 1

cp -a preserves ownership, permissions and timestamps. A plain cp -r run under sudo rewrites them, which can leave the restored volume unreadable by the Weaviate container.

In production, prefer Weaviate's backup module writing to S3, GCS, or Azure. It produces a restorable snapshot rather than a raw directory copy, and it can run against a live instance. The local filesystem backend is for development only.

Upgrade One Minor at a Time

Move through every minor release in order, always landing on that minor's latest patch.

Step Image tag
0 (current) semitechnologies/weaviate:1.27.0
1 cr.weaviate.io/semitechnologies/weaviate:1.27.27
2 cr.weaviate.io/semitechnologies/weaviate:1.28.16
3 cr.weaviate.io/semitechnologies/weaviate:1.29.11
4 cr.weaviate.io/semitechnologies/weaviate:1.30.23
5 cr.weaviate.io/semitechnologies/weaviate:1.31.22
6 cr.weaviate.io/semitechnologies/weaviate:1.32.27
7 cr.weaviate.io/semitechnologies/weaviate:1.33.18
8 cr.weaviate.io/semitechnologies/weaviate:1.34.20
9 cr.weaviate.io/semitechnologies/weaviate:1.35.23
10 cr.weaviate.io/semitechnologies/weaviate:1.36.23
11 cr.weaviate.io/semitechnologies/weaviate:1.37.16
12 cr.weaviate.io/semitechnologies/weaviate:1.38.14
13 cr.weaviate.io/semitechnologies/weaviate:1.39.2

The registry changes at step 1. Existing deployments pull semitechnologies/weaviate from Docker Hub; the ladder uses cr.weaviate.io/semitechnologies/weaviate, Weaviate's own registry, which is what Dify's updated Compose file points at. The images are the same, so you are changing both registry and version as one deliberate move.

Patch versions were current at the time of writing. For the intermediate rungs, check for a newer patch of that minor before you start and prefer it.

The final rung is the exception. Land on the version your docker-compose.yaml pins, not the newest patch available. If you take the volume to a newer patch and then apply Dify's pin, you have downgraded onto a volume the newer binary already wrote to—the case the rollback warning covers.

Stepping one minor at a time also limits your blast radius. When a rung misbehaves, you roll back a single version and know exactly which release caused it, instead of bisecting a jump that crossed every minor at once.

Staying close to the newest release keeps you in the fix window. Weaviate supports the three most recent minor versions—the current one and the two before it. Anything older is end of life and has no claim on bug or security fixes. Revisit periodically after this migration and move to the current patch.

Upgrade with Docker Compose

Dify pins the Weaviate image in docker/docker-compose.yaml, docker/docker-compose.middleware.yaml, and docker/docker-compose-template.yaml. Edit the file you deploy with, then repeat the loop below for each rung.

Change the `weaviate` service to the next minor's latest patch, for example `image: cr.weaviate.io/semitechnologies/weaviate:1.28.16`.
docker compose stop -t -1 weaviate || exit 1
Never use `docker kill` or `docker rm -f` here. See [Stop Weaviate Gracefully](#stop-weaviate-gracefully) for what a hard kill costs you.
docker compose up -d weaviate
Run [Verify Each Step](#verify-each-step) before continuing.

If you run Weaviate through docker-compose.middleware.yaml while developing from source, the same loop applies with the file named explicitly:

docker compose -f docker-compose.middleware.yaml stop -t -1 weaviate || exit 1
docker compose -f docker-compose.middleware.yaml --profile weaviate up -d weaviate

Stop Weaviate Gracefully

This is the single detail most likely to cost you working search, and it is easy to get wrong.

Weaviate holds its HNSW vector index in memory and records it to disk through a commit log. When the container is hard-killed—docker kill, docker rm -f, an out-of-memory kill, or a stop that exceeds Docker's grace period—that commit log can be left incomplete, and objects it had not yet recorded end up missing from the graph.

Your objects are not lost. The graph is. Testing this on 1.39.2, a hard kill immediately after importing 500 objects into a 700-object collection left it like this:

Check Result
Object count 700, correct
Listing all objects returns all 700
Keyword (BM25) search finds all 500 imported objects
Fetch by ID returns exact vectors
near_vector with limit: 700 680

Twenty objects sat in the store, fully intact, and vector search could not reach them.

What makes this dangerous is that nothing announces it. The server logged no error, no warning, and nothing at all about the commit log—there is no line to grep for. And the object count, the check most people reach for first, reads perfectly healthy.

It also does not heal on its own. The same twenty stayed missing after the restart, after a graceful stop and start, after a second one, and after re-writing the same objects. To repair it, re-index the affected knowledge base in Dify so the collection is built again from scratch.

So prevention is the whole game here. Use docker compose stop or docker compose down, both of which send SIGTERM, and let the process finish flushing. A timeout of -1 waits indefinitely instead of falling back to SIGKILL:

docker compose stop -t -1 weaviate || exit 1

To check whether it already happened, compare the object count against what vector search can actually reach. Verify Each Step gives you the count; run a near_vector query with limit set to that number. Fewer results back means the difference is your unreachable objects.

Wait for the Index to Mount After Each Restart

/v1/meta starts answering about two seconds after the container starts, on every version on the ladder. Your collections take longer to mount, and from 1.31 onward they take much longer—measured across the whole ladder, the gap between /v1/meta answering and the first successful collection query is:

Server version Gap before queries work
1.27 - 1.30 under 0.3s
1.31 and later 4 - 9s

A query fired inside that window does not report "still starting". It reports that your data is not there:

  • GET /v1/objects?class=... returns 404 with an empty body.
  • A GraphQL query returns 422 with no graphql provider present, this is most likely because no schema is present. Import a schema first!

That is alarming to read halfway through an upgrade, and it is a false alarm. The window is transient and needs no action beyond waiting. Give each restart ten seconds before you conclude anything, and if you script health checks, poll until a real collection query succeeds rather than trusting /v1/meta alone.

Verify Each Step

Confirm that data survived and that search works. A server that boots is not evidence of a healthy index.

Set your key and collection name once, then run the four checks. Dify replaces every hyphen in the knowledge base ID with an underscore when it names the collection, so copy the exact name from the second check rather than building it by hand:

KEY="<WEAVIATE_API_KEY>"
# Knowledge base ID from its Dify URL (/datasets/<id>/documents), hyphens as underscores
COLLECTION="Vector_index_9f4e2b7a_1c3d_4e5f_8a9b_0c1d2e3f4a5b_Node"

# Reported server version
docker compose exec -T weaviate \
  wget -qO- --header="Authorization: Bearer $KEY" http://localhost:8080/v1/meta \
  | python3 -c "import sys, json; print('version', json.load(sys.stdin)['version'])"

# Collections are present
docker compose exec -T weaviate \
  wget -qO- --header="Authorization: Bearer $KEY" http://localhost:8080/v1/schema \
  | python3 -c "import sys, json; print([c['class'] for c in json.load(sys.stdin)['classes']])"

# Object count for one collection
docker compose exec -T weaviate \
  wget -qO- --header="Authorization: Bearer $KEY" \
  --header="Content-Type: application/json" \
  --post-data="{\"query\":\"{ Aggregate { $COLLECTION { meta { count } } } }\"}" \
  http://localhost:8080/v1/graphql \
  | python3 -c "import sys, json; print('count', json.load(sys.stdin)['data']['Aggregate']['$COLLECTION'][0]['meta']['count'])"

# Single-node metadata is synchronized
docker compose exec -T weaviate \
  wget -qO- --header="Authorization: Bearer $KEY" \
  http://localhost:8080/v1/cluster/statistics \
  | python3 -c "import sys, json; d=json.load(sys.stdin); assert d.get('synchronized') is True and len(d.get('statistics', [])) == 1; print('synchronized')"

Continue only if the reported version matches the current rung, the object count is unchanged, and the synchronization check succeeds.

Do not use GET /v1/objects?class=...&limit=1 to count objects. Its totalResults field reports the size of the page it returned, not the size of the collection, so with limit=1 it always prints 1. Use the Aggregate query above.

After 1.39.2 passes, run docker compose stop -t -1 weaviate || exit 1. Revert only the temporary image edit without running Compose, then follow the Docker Compose upgrade instructions for Dify 1.17.1. Run a test retrieval before returning the deployment to service; getting chunks back confirms the vector index survived, which the object count alone does not tell you.

Roll Back a Failed Step

Before starting Dify 1.17.1, set the Weaviate image back to semitechnologies/weaviate:1.27.0, then restore the initial backup:

docker compose stop -t -1 weaviate || exit 1
test -d ./volumes/weaviate_backup_YYYYMMDD || exit 1
sudo mv ./volumes/weaviate ./volumes/weaviate_failed_$(date +%Y%m%dT%H%M%S) || exit 1
sudo cp -a ./volumes/weaviate_backup_YYYYMMDD ./volumes/weaviate || exit 1
docker compose up -d weaviate

Rolling the image tag back without restoring the data is not safe. Once a newer version has written to the volume, an older binary may not read it.

Verify Weaviate, then start the original Dify stack and run a test retrieval.

What Does Not Change

Your collections keep their existing layout, so no re-indexing is required and your knowledge bases keep working as they are. Dify stores each dataset as a Vector_index_<dataset_id>_Node collection, with the ID's hyphens replaced by underscores, and a self-provided named vector default. Dify does not set a distance metric, so the collection uses the server default of cosine. That structure is identical before and after the upgrade.

The Python weaviate-client also needs no attention. Use the version your Dify release pins: 4.20.5 for Dify 1.14.0 through 1.16.1, and 4.22.0 for 1.17.0 through 1.17.1. Both work against every server version on the ladder, so you can upgrade the server independently of Dify.

Running a Weaviate server older than 1.27, or moving from client v3 to v4? Start with the Weaviate v4 migration guide, which covers 1.19.0 through 1.26.x and the schema migration up to 1.27, then return here.


Authentication & Access

Reset admin password

For Docker Compose deployments:

docker exec -it docker-api-1 flask reset-password

Enter the account email and new password when prompted.

For source code deployments, run the same command from the api directory.

401 errors after login

This typically happens after changing domains. Update these environment variables:

  • CONSOLE_CORS_ALLOW_ORIGINS - Console CORS policy
  • WEB_API_CORS_ALLOW_ORIGINS - Web app CORS policy
  • CONSOLE_API_URL - Backend URL for console API
  • CONSOLE_WEB_URL - Frontend URL for console web
  • SERVICE_API_URL - Service API URL
  • APP_API_URL - Web app API backend URL
  • APP_WEB_URL - Web app URL

Restart after updating configuration.

Configuration

Change default port

Modify .env configuration:

EXPOSE_NGINX_PORT=80
EXPOSE_NGINX_SSL_PORT=443

For API service port changes, update the nginx configuration in docker-compose.yaml.

Increase file upload limits

Update in .env:

  • UPLOAD_FILE_SIZE_LIMIT - Maximum file size
  • NGINX_CLIENT_MAX_BODY_SIZE - Must match to avoid issues

Workflow complexity limits

Adjust MAX_TREE_DEPTH in web/app/components/workflow/constants.ts (default: 50).

Note: Excessive depth impacts performance.

Node execution timeout

Set TEXT_GENERATION_TIMEOUT_MS in .env to control runtime per node.

Email Configuration

Not receiving password reset emails? Configure mail settings in .env:

  1. Set up mail parameters (SMTP settings)
  2. Restart services:
docker compose down
docker compose up -d

Check spam folder if emails still don't arrive.

Invite members without email service

In local deployments without email configured, the invitation page displays a link after sending. Copy and forward this link to users manually.

Database Issues

Connection errors with pg_hba.conf

If you see:

FATAL: no pg_hba.conf entry for host "172.19.0.7", user "postgres", database "dify", no encryption

Allow connections from the error's network segment:

docker exec -it docker-db-1 sh -c "echo 'host all all 172.19.0.0/16 trust' >> /var/lib/postgresql/data/pgdata/pg_hba.conf"
docker-compose restart

File not found error for encryption keys

This error occurs after changing deployment methods or deleting api/storage/privkeys:

FileNotFoundError: File not found
File "/www/wwwroot/dify/dify/api/libs/rsa.py", line 45, in decrypt

Reset encryption key pairs:

Docker Compose:

docker exec -it docker-api-1 flask reset-encrypt-key-pair

Source code (from api directory):

flask reset-encrypt-key-pair

This is irreversible. Existing LLM credentials and tool credentials (built-in, custom, and MCP tools) are purged for every workspace and must be re-entered.

Workspace Management

Rename workspace

Modify the tenants table in the database directly.

Change application access domain

Update APP_WEB_URL in docker-compose.yaml.


Vector Database Migration

Migrate from Weaviate to another database

  1. Update configuration

Source code deployment (.env):

VECTOR_STORE=qdrant

Docker Compose (docker-compose.yaml):

VECTOR_STORE: qdrant
  1. Run migration
# Source code
flask vdb-migrate

# Docker
docker exec -it docker-api-1 flask vdb-migrate

Tested databases: Qdrant, Milvus, AnalyticDB

Storage Migration

Move from local to cloud storage

Migrate files from local storage to cloud providers (e.g., Alibaba Cloud OSS):

  1. Configure cloud storage

.env or docker-compose.yaml:

STORAGE_TYPE=aliyun-oss
# Add OSS credentials
  1. Migrate data

Source code:

flask upload-private-key-file-to-cloud-storage
flask upload-local-files-to-cloud-storage

Docker:

docker exec -it docker-api-1 flask upload-private-key-file-to-cloud-storage
docker exec -it docker-api-1 flask upload-local-files-to-cloud-storage

Data Cleanup

Delete old logs

  1. Get tenant ID
docker exec -it docker-api-1 bash -c "echo 'from models import Tenant; db.session.query(Tenant.id, Tenant.name).all(); quit()' | flask shell"
  1. Delete logs older than X days
docker exec -it docker-api-1 flask clear-free-plan-tenant-expired-logs \
  --days 30 \
  --batch 100 \
  --tenant_ids 618b5d66-a1f5-4b6b-8d12-f171182a1cb2
  1. Remove exported logs (optional)
docker exec -it docker-api-1 bash -c 'rm -rf ${OPENDAL_FS_ROOT}/free_plan_tenant_expired_logs'

Remove orphaned files

Warning: Back up database and storage before running. Run during maintenance window.

  1. Clean database records
docker exec -it docker-api-1 flask clear-orphaned-file-records
# Use -f flag to skip confirmation
  1. Delete orphaned files from storage
docker exec -it docker-api-1 flask remove-orphaned-files-on-storage
# Use -f flag to skip confirmation

Note: Only works with OpenDAL storage (STORAGE_TYPE=opendal).

Backup & Recovery

Create backup before upgrade

cp -r dify "dify.bak.$(date +%Y%m%d%H%M%S)"

What to backup

For Docker Compose deployments:

  • Entire dify/docker/volumes directory

For source deployments:

  • Database
  • Storage configuration
  • Vector database data
  • Environment files

Database maintenance

After deleting logs, reclaim storage:

PostgreSQL:

VACUUM FULL;

Upgrade Process

Version upgrade

Image deployment:

docker compose pull
docker compose up -d

Source code:

git pull
cd api
flask db upgrade

Database schema migration

Always required for source code updates:

cd api
flask db upgrade

Network & Connectivity

502 Bad Gateway

Nginx is forwarding to wrong container IPs. Get current container IPs:

docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }}: {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'

Find these lines:

/docker-web-1: 172.19.0.5
/docker-api-1: 172.19.0.7

Update dify/docker/nginx/conf.d:

  • Replace http://api:5001 with http://172.19.0.7:5001
  • Replace http://web:3000 with http://172.19.0.5:3000

Restart nginx or reload configuration. Note: IPs change on container restart.

Cannot access localhost services

Docker containers can't reach host services via 127.0.0.1. Use your machine's local network IP instead.

Example: For OpenLLM running on host, configure Dify with http://192.168.1.100:port (your actual local IP).

Page loads forever with CORS errors

Domain/URL changes cause cross-origin issues. Update in docker-compose.yml:

  • CONSOLE_API_URL - Backend URL for console API
  • CONSOLE_WEB_URL - Frontend URL for console web
  • SERVICE_API_URL - Service API URL
  • APP_API_URL - Web app API backend URL
  • APP_WEB_URL - Web app URL

Mounting & Volumes

Nginx configuration mount failure

Error:

Error mounting "/run/desktop/mnt/host/d/Documents/docker/nginx/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": not a directory

Clone the complete project and run from docker directory:

git clone https://github.com/langgenius/dify.git
cd dify/docker
docker compose up -d

Port conflicts

Port 80 already in use? Either:

  1. Stop the conflicting service (usually Apache/Nginx):
sudo service nginx stop
sudo service apache2 stop
  1. Or change port mapping in docker-compose.yaml:
ports:
  - "8080:80"  # Map to different port

Container Management

View background shell outputs

List running shells:

docker exec -it docker-api-1 ls /tmp/shells/

Check shell output:

docker exec -it docker-api-1 cat /tmp/shells/[shell-id]/output.log

Container restart issues

After system reboot, containers may fail to connect. Ensure proper startup order:

docker compose down
docker compose up -d

Wait for all services to be healthy before accessing.

SSRF Proxy

The ssrf_proxy container prevents Server-Side Request Forgery attacks.

Customize proxy rules

Edit docker/volumes/ssrf_proxy/squid.conf to add ACL rules:

# Block access to sensitive internal IP
acl restricted_ip dst 192.168.101.19
acl localnet src 192.168.101.0/24

http_access deny restricted_ip
http_access allow localnet
http_access deny all

Restart the proxy container after changes.

Why is SSRF_PROXY needed?

Prevents services from making unauthorized requests to internal network resources. The proxy intercepts and filters all outbound requests from sandboxed services.


Notion Integration

Notion OAuth only supports HTTPS, so local deployments must use internal integration.

Configure environment variables

Set in .env:

NOTION_INTEGRATION_TYPE=internal
NOTION_INTERNAL_SECRET=your_internal_secret_here

For public integration (HTTPS only):

NOTION_INTEGRATION_TYPE=public
NOTION_CLIENT_SECRET=oauth_client_secret
NOTION_CLIENT_ID=oauth_client_id

Get credentials from Notion Integrations.

Text-to-Speech (TTS)

FFmpeg not installed error

OpenAI TTS requires FFmpeg for audio stream segmentation.

macOS:

brew install ffmpeg

Ubuntu:

sudo apt-get update
sudo apt-get install ffmpeg

CentOS:

sudo yum install epel-release
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
sudo yum update
sudo yum install ffmpeg ffmpeg-devel

Windows:

  1. Download from FFmpeg website
  2. Extract and move to C:\Program Files\
  3. Add FFmpeg bin directory to system PATH
  4. Verify: ffmpeg -version

Model Tokenizers

Can't load tokenizer for 'gpt2'

Error:

Can't load tokenizer for 'gpt2'. If you were trying to load it from 'https://huggingface.co/models'...

Configure Hugging Face mirror or proxy in environment variables. See environment documentation for details.

Security Policies

Content Security Policy (CSP)

Enable CSP to reduce XSS attacks.

In .env:

CSP_WHITELIST=https://api.example.com,https://cdn.example.com

Add all domains used by your application (APIs, CDNs, analytics, etc.).

See MDN CSP documentation for more information.