> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy Dify with Docker Compose

> Run Dify on one machine with Docker Compose, then secure, customize, and upgrade it

> [!TIP]
>
> The default Docker Compose deployment runs Dify with bundled PostgreSQL, Weaviate, and the other services it needs, so you don't set up a database or vector store first.

## Before Deployment

### Hardware

* **CPU**: at least 2 cores
* **RAM**: at least 4 GiB

### Software

Install Docker with Docker Compose 2.35.0 or later, and make sure the Docker daemon is running. You also need Git to download Dify, and OpenSSL to generate a token for the agent's local sandbox.

| Operating System | Installation |
| :- | :- |
| macOS | Install [Docker Desktop for Mac](https://docs.docker.com/desktop/setup/install/mac-install/). Configure its virtual machine with at least 2 virtual CPUs and 8 GiB of memory. |
| Linux | Install [Docker Engine](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/) for your distribution. |
| Windows with WSL 2 | Install [Docker Desktop for Windows](https://docs.docker.com/desktop/setup/install/windows-install/). Store the source code and container data in the Linux file system. |

Check the Compose version before starting:

```bash theme={null}
docker compose version
```

## Deploy and Start

> [!NOTE]
>
> For an existing deployment, follow [Upgrade](#upgrade) instead to keep its configuration and data.

**1. Get a Dify Release**

Choose a version from [Dify releases](https://github.com/langgenius/dify/releases) and clone it, replacing `<version>` with its tag:

```bash theme={null}
git clone --branch <version> --depth 1 https://github.com/langgenius/dify.git
cd dify/docker
```

**2. Configure Startup Settings**

Create the configuration file from its template:

```bash theme={null}
cp .env.example .env
```

Generate a token for the agent's local sandbox:

```bash theme={null}
openssl rand -hex 32
```

In `.env`, set `DIFY_AGENT_LOCAL_SANDBOX_AUTH_TOKEN` to the output. The agent backend and its local sandbox require this shared token to start.

> [!TIP]
>
> Before the first start:
>
> * For production, set the credentials in [Secure the Deployment](#secure-the-deployment).
> * To use another bundled vector store or MySQL instead of Weaviate and PostgreSQL, set it in `.env`. Switching after the first start doesn't move existing data. See [VECTOR\_STORE](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#vector_store) and [Database Configuration](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#database-configuration) for the settings each needs.

**3. Start and Check the Services**

From `dify/docker`, run:

```bash theme={null}
docker compose up -d
docker compose ps --all
```

Long-running services should show `Up` or `healthy`. The `init_permissions` task runs once to prepare storage permissions and shows `Exited (0)` when it's done.

## Access

Open `http://localhost/install` in your browser and create the administrator account, then sign in at `http://localhost`.

For a remote deployment, replace `localhost` with the server's IP address or domain. The default HTTP port is `80`. If port 80 is in use, set [`EXPOSE_NGINX_PORT`](https://docs.dify.ai/en/self-host/deploy/configuration/environments#docker-compose) in `docker/.env` to another port, and add that port to the address.

> [!TIP]
>
> For real-time collaboration on a remote server, add [`NEXT_PUBLIC_SOCKET_URL`](https://docs.dify.ai/en/self-host/deploy/configuration/environments#cors-configuration) to `docker/.env` with the server's WebSocket address, then run `docker compose up -d`.

## Customize

Put deployment-wide settings in `docker/.env`: Compose profiles, published ports, mount paths, health-check scheduling, and the shared credentials in [Secure the Deployment](#secure-the-deployment).

To use your own domain, [check whether you need to set the public URLs](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#common-variables).

Other settings belong to a service. Most services load their bundled `.defaults` files under `docker/envs/`; leave those as they are and put your changes in the local `.env` file named in their comments. Settings shared by the API, workers, and scheduled tasks go in `envs/core-services/api-worker.env`.

For example, to raise Nginx's maximum request body size to `200M`, run these from `dify/docker`:

**1. Set the Override**

If `envs/infrastructure/nginx.env` doesn't exist, create it:

```bash theme={null}
cp envs/infrastructure/nginx.defaults envs/infrastructure/nginx.env
```

In `envs/infrastructure/nginx.env`, set:

```dotenv theme={null}
NGINX_CLIENT_MAX_BODY_SIZE=200M
```

**2. Apply the Change**

Validate the configuration and recreate the affected containers:

```bash theme={null}
docker compose config --quiet
docker compose up -d
```

Use `up -d`, not `docker compose restart`: `restart` keeps the containers' old environment.

**3. Check the Active Value**

Read Nginx's active configuration:

```bash theme={null}
docker compose exec -T nginx nginx -T 2>&1 | grep client_max_body_size
```

The output should include `client_max_body_size 200M;`. If it shows another value, check `docker/.env` for an override, then see [Precedence](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#precedence) for the other places a value can come from.

For every variable and the full precedence rules, see [Environment Variables](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#configuration-files).

## Secure the Deployment

Before others can reach the deployment, configure [HTTPS](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#nginx-reverse-proxy) and replace the bundled development credentials in `docker/.env`:

* **Database and Redis**: `DB_PASSWORD` and `REDIS_PASSWORD`.
* **Code sandbox**: Set `SANDBOX_API_KEY` and `CODE_EXECUTION_API_KEY` to the same strong secret. See [Sandbox Service](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#sandbox-service) for details.
* **Weaviate**: Set `WEAVIATE_API_KEY` to a strong secret that's also listed in `WEAVIATE_AUTHENTICATION_APIKEY_ALLOWED_KEYS`, and set `WEAVIATE_AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=false` to require authentication. See [Vector Database Service Configuration](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#vector-database-service-configuration) for details.
* **Plugin daemon**: Set `PLUGIN_DAEMON_KEY` and `PLUGIN_DIFY_INNER_API_KEY` to separate strong values. See [Plugin Daemon Configuration](https://docs.dify.ai/en/self-host/deploy/configuration/environments.md#plugin-daemon-configuration) for details.
* **Agent**: Replace [`DIFY_AGENT_API_TOKEN`](https://docs.dify.ai/en/self-host/deploy/configuration/environments#dify_agent_api_token) and generate [`DIFY_AGENT_SERVER_SECRET_KEY`](https://docs.dify.ai/en/self-host/deploy/configuration/environments#dify_agent_server_secret_key) in its required format. Keep the [`DIFY_AGENT_LOCAL_SANDBOX_AUTH_TOKEN`](https://docs.dify.ai/en/self-host/deploy/configuration/environments#dify_agent_local_sandbox_auth_token) you generated at startup.

If Dify is already running, apply the new values with `docker compose up -d`. The database password is the exception: once the database is initialized, change the password on the database server first, then update `DB_PASSWORD` to match.

> [!NOTE]
>
> Leave `SECRET_KEY` as it is: unless you set one, Dify generates a random key on first start and stores it with its data. Setting or changing it later stops tokens and file links signed with the old key from working; see [`SECRET_KEY`](https://docs.dify.ai/en/self-host/deploy/configuration/environments#secret_key) for everything it affects.

The default stack publishes no host ports for the database, Redis, Code sandbox, or Weaviate. Restrict access to them on the private network too.

## Upgrade

Choose the target release on [Dify releases](https://github.com/langgenius/dify/releases) and read its upgrade guide first.

Run every Compose command below with the deployment's existing project name and options, including any `-p`, `-f`, `--env-file`, profiles, or `COMPOSE_PROJECT_NAME`, so its named volumes stay attached and the same configuration is loaded.

**1. Back Up the Deployment**

1. From `dify/docker`, stop the deployment so the databases aren't writing while you copy their files:

   ```bash theme={null}
   docker compose stop
   ```

   If you can't stop it, back up the databases with their own dump tools instead.

2. Back up `docker/.env`, your local service `.env` files, any custom Compose files, and persistent data, including `docker/volumes/` and any external databases and storage.

3. If your deployment includes `local_sandbox`, also back up its named volumes, mounted at `/home/dify` and `/workspace`. Their names carry the Compose project prefix; list them with:

   ```bash theme={null}
   docker inspect --format '{{range .Mounts}}{{if eq .Type "volume"}}{{println .Name .Destination}}{{end}}{{end}}' "$(docker compose ps --all --quiet local_sandbox)"
   ```

4. Save the output of `docker compose config` to compare after the update. It contains secrets, so keep it private.

**2. Update to the New Release**

Git doesn't track your local `.env` files or the data in `docker/volumes/`, so checking out a release leaves them in place. If you edited tracked files such as `docker-compose.yaml`, stash those edits first. From the repository root:

```bash theme={null}
git stash
git fetch --tags origin
git checkout <version>
```

Then reapply your edits to the new release's files, for example with `git stash pop`, and resolve any conflicts.

**3. Review Your Configuration**

Compare `docker/.env.example` with your `docker/.env`, and each local service file with its `.defaults` or `.env.example` template.

Update your existing files with the settings you need; copying a template over them discards your overrides. If a setting has a new name in the template, use the new name. Leave the lines under **Container variable mappings** unchanged.

Keep the existing database and every vector store your knowledge bases still use, with their connection settings and Compose profiles. Changing `DB_TYPE` or `VECTOR_STORE` doesn't migrate data.

Finally, compare the new `docker compose config` output with the copy you saved: check credentials, volume paths, profiles, and the settings you customized.

**4. Apply and Check the Upgrade**

From `dify/docker`, run:

```bash theme={null}
docker compose config --quiet
docker compose pull
docker compose up -d
docker compose ps --all
```

Long-running services should show `Up` or `healthy`, and `init_permissions` should show `Exited (0)`. Then open Dify and try the features that use your custom settings.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.