How to self-host Dify using Docker

Introduction

This guide explains how to install and run Dify on your local machine using Docker. By following these steps, you will clone the Dify source code, configure the environment, and start the necessary containers.

Prerequisites

  • Docker installed on your system (View guide)
  • Git installed (use: sudo apt install git)
  • Basic familiarity with command-line usage

Cloning the Dify Source Code

Clone the Dify repository from GitHub to your local machine. Replace 0.15.3 with the latest version if applicable.

Bash
# Clone the repository
git clone https://github.com/langgenius/dify.git --branch 0.15.3

Change to the Docker directory within the cloned repository:

Bash
cd dify/docker

Configuring the Environment

Copy the example environment configuration file to create a working .env file:

Bash
cp .env.example .env

Starting the Docker Containers

Start the necessary Docker containers using the appropriate command based on your Docker Compose version.

Check Docker Compose Version

To determine your Docker Compose version, run:

Bash
docker compose version

Start Containers with Docker Compose V2

If using Docker Compose V2, start the containers with:

Bash
docker compose up -d

Start Containers with Docker Compose V1

If using Docker Compose V1, use:

Bash
docker-compose up -d

Check the status

Bash
docker compose ps

The output should list the core services and their statuses:

Bash
NAME                  IMAGE                              COMMAND                   SERVICE      STATUS            PORTS
docker-api-1          langgenius/dify-api:0.6.13         "/bin/bash /entrypoi…"   api          Up                5001/tcp
docker-db-1           postgres:15-alpine                 "docker-entrypoint.s…"   db           Up (healthy)      5432/tcp
docker-nginx-1        nginx:latest                       "sh -c 'cp /docker-e…"   nginx        Up                0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
...

Dify runs three core services (api, worker, and web) and six dependent components (weaviate, db, redis, nginx, ssrf_proxy, and sandbox).

Conclusion

After completing these steps, Dify should be running successfully on your local machine. You can now start using it for your development and testing needs.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *