Implementation:Langgenius Dify Docker Compose Up
| Knowledge Sources | Dify |
|---|---|
| Domains | DevOps, Deployment, Docker, Orchestration |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for launching the complete Dify application stack using docker compose up -d, provided by the docker/docker-compose.yaml orchestration file.
Description
The docker compose up -d command reads the docker-compose.yaml file (lines 697-1626) along with the .env file and starts all services in detached mode. The compose file defines the following core service topology:
| Service | Image | Role | Port | Key Configuration |
|---|---|---|---|---|
| api | langgenius/dify-api:1.13.0 | Flask + Gunicorn (gevent) REST API | 5001 (internal) | MODE=api, shared env anchor |
| worker | langgenius/dify-api:1.13.0 | Celery worker for background tasks | None | MODE=worker, shared env anchor |
| worker_beat | langgenius/dify-api:1.13.0 | Celery Beat periodic scheduler | None | MODE=beat, shared env anchor |
| web | langgenius/dify-web:1.13.0 | Next.js frontend via PM2 | Internal only | PM2_INSTANCES=2 |
| nginx | nginx:latest | Reverse proxy | 80, 443 | Routes /api to api, / to web |
| db_postgres | postgres:15-alpine | PostgreSQL metadata DB | 5432 (internal) | Profile: postgresql |
| redis | redis:6-alpine | Cache + Celery broker | 6379 (internal) | Password-protected |
| sandbox | langgenius/dify-sandbox:0.2.12 | Code execution sandbox | 8194 (internal) | SSRF proxy network |
| plugin_daemon | langgenius/dify-plugin-daemon:0.5.3-local | Plugin lifecycle manager | 5002, 5003 | DIFY_INNER_API_KEY for auth |
| ssrf_proxy | ubuntu/squid:latest | Squid SSRF protection proxy | 3128 (internal) | Internal network only |
| init_permissions | busybox:latest | Volume ownership init | None | Runs once, exits |
The startup sequence follows the dependency graph:
init_permissionsruns and completes (sets UID 1001 on storage)db_postgresstarts and becomes healthy (pg_isready)redisstartsapi,worker,worker_beatstart (depend on init, db, redis)webstarts (no dependencies)nginxstarts (depends on api and web)sandbox,ssrf_proxy,plugin_daemonstart in parallel
Usage
Run this command from the docker/ directory after configuring the .env file. This is the primary entry point for deploying Dify.
Code Reference
Source Location: docker/docker-compose.yaml, lines 697-1626
Signature:
cd docker
docker compose up -d
Import statement: Not applicable (Docker Compose CLI command).
I/O Contract
Inputs
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| .env file | File | No (defaults used) | docker/.env | Environment variable overrides for all services |
| docker-compose.yaml | File | Yes | docker/docker-compose.yaml | Service definitions, dependencies, and network configuration |
| COMPOSE_PROFILES | String | No | weaviate,postgresql | Comma-separated list of profiles to activate (vector DB + metadata DB) |
| -d flag | CLI flag | No | N/A | Detached mode; containers run in background |
Outputs
| Output | Type | Description |
|---|---|---|
| Running containers | Docker containers | All services started according to dependency order and profile selection |
| Exposed ports | Network bindings | nginx on ports 80/443, plugin_daemon debug on 5003 |
| Named volumes | Docker volumes | Persistent data for db, redis, vector store, app storage, sandbox |
| Docker networks | Bridge networks | default, ssrf_proxy_network (internal), milvus (if active), opensearch-net (if active) |
Usage Examples
Standard deployment:
cd docker
cp .env.example .env
# Edit .env as needed (SECRET_KEY, passwords, etc.)
docker compose up -d
Check service status after launch:
docker compose ps
# NAME STATUS PORTS
# api running 5001/tcp
# worker running
# worker_beat running
# web running
# nginx running 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp
# db_postgres running (healthy)
# redis running (healthy)
# sandbox running (healthy)
# plugin_daemon running 0.0.0.0:5003->5003/tcp
# ssrf_proxy running
# weaviate running
View logs for a specific service:
docker compose logs -f api
docker compose logs -f worker
Restart only the API service:
docker compose restart api
Scale Celery workers (not supported directly via replicas due to volume mounts, but possible with override):
# Adjust CELERY_WORKER_AMOUNT in .env to control concurrency within a single worker
# Or use CELERY_AUTO_SCALE=true with CELERY_MAX_WORKERS and CELERY_MIN_WORKERS
Tear down the entire stack:
docker compose down
# Add -v to also remove volumes (WARNING: destroys data)