安装 Docker 和 Docker Compose
ubuntu版本
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.4 LTS"
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
c
# 安装Docker
sudo apt update
sudo apt install -y docker.io
# 启动Docker服务
sudo systemctl start docker
sudo systemctl enable docker
# 安装Docker Compose
sudo apt install -y docker-compose
# 将当前用户添加到docker组(避免每次使用sudo)
sudo usermod -aG docker $USER
获取 Dify 源码
c
# 克隆Dify仓库
git clone https://github.com/langgenius/dify.git
4.4 配置环境变量
进入到如下目录:
c
cd dify/docker
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# ls -a
. .env.example
.. envs
certbot generate_docker_compose
couchbase-server .gitignore
dify-env-sync.py iris
dify-env-sync.sh nginx
docker-compose.middleware.yaml pgvector
docker-compose.png README.md
docker-compose.pytest.ports.yaml ssrf_proxy
docker-compose-template.yaml startupscripts
docker-compose.yaml tidb
elasticsearch volumes
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
复制环境变量示例文件
c
cp .env.example .env
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# # 复制环境变量示例 文件
cp .env.example .env
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# ls -a
. docker-compose-template.yaml nginx
.. docker-compose.yaml pgvector
certbot elasticsearch README.md
couchbase-server .env ssrf_proxy
dify-env-sync.py .env.example startupscripts
dify-env-sync.sh envs tidb
docker-compose.middleware.yaml generate_docker_compose volumes
docker-compose.png .gitignore
docker-compose.pytest.ports.yaml iris
docker安装
c
# 重新安装
sudo apt update
sudo apt install -y docker.io docker-compose
# 启动服务
sudo systemctl start containerd
sudo systemctl start docker
# 将当前用户添加到docker组(避免每次使用sudo)
sudo usermod -aG docker $USER
c
sudo apt update
sudo apt install -y docker.io docker-compose
# 启动服务
sudo systemctl start containerd
sudo systemctl start docker
# 将当前用户添加到docker组(避免每次使用sudo)
sudo usermod -aG docker $USER
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
28 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
docker.io is already the newest version (29.1.3-0ubuntu3~24.04.2).
docker-compose is already the newest version (1.29.2-6ubuntu1).
The following packages were automatically installed and are no longer required:
graphicsmagick libfwupd2 libgraphicsmagick-q16-3t64
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# vi /etc/docker/daemon.json
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
打开 Docker 的配置文件:
c
sudo vim /etc/docker/daemon.json
代码如下
c
{
"registry-mirrors": [
"https://docker.xuanyuan.me",
"https://docker.1ms.run"
]
}
重启 Docker 服务:
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# sudo systemctl daemon-reload
sudo systemctl restart docker
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
启动容器报错
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# docker compose up -d
unknown shorthand flag: 'd' in -d
Usage: docker [OPTIONS] COMMAND [ARG...]
Run 'docker --help' for more information
安装新版 Docker Compose 插件(推荐)
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# sudo apt-get update
sudo apt-get install docker-compose-plugin
```<websource>source_group_web_3</websource>
### 3. 验证安装
安装完成后,再次验证版本:
```bash
docker compose version
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package docker-compose-plugin
bash: command substitution: line 88: syntax error near unexpected token `newline'
bash: command substitution: line 88: `<websource>source_group_web_3</websource>'
docker: unknown command: docker compose
Run 'docker --help' for more information
添加 Docker 官方源
c
# 添加密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 添加软件源
echo "deb [arch=$(dpkg --print-architecture)] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# # 添加密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 添加软件源
echo "deb [arch=$(dpkg --print-architecture)] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Command 'curl' not found, but can be installed with:
snap install curl # version 8.21.0, or
apt install curl # version 8.5.0-2ubuntu10.10
See 'snap info curl' for additional versions.
gpg: no valid OpenPGP data found.
deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble stable
```c
```c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# apt install curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
graphicsmagick libfwupd2 libgraphicsmagick-q16-3t64
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
curl
0 upgraded, 1 newly installed, 0 to remove and 28 not upgraded.
Need to get 226 kB of archives.
After this operation, 535 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates/main amd64 curl amd64 8.5.0-2ubuntu10.11 [226 kB]
Fetched 226 kB in 1s (388 kB/s)
Selecting previously unselected package curl.
(Reading database ... 161266 files and directories currently installed.)
Preparing to unpack .../curl_8.5.0-2ubuntu10.11_amd64.deb ...
Unpacking curl (8.5.0-2ubuntu10.11) ...
Setting up curl (8.5.0-2ubuntu10.11) ...
Processing triggers for man-db (2.12.0-4build2) ...
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# echo "deb [arch=$(dpkg --print-architecture)] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble stable
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
更新软件包索引并安装
添加完源之后,更新一下本地缓存,然后安装 Docker Compose 插件:
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# sudo apt-get update
sudo apt-get install docker-compose-plugin
Get:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease [48.5 kB]
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease
Err:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
Hit:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
W: GPG error: https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
E: The repository 'https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package docker-compose-plugin
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
导入缺失的 GPG 密钥
请在终端中运行以下命令,这会将缺失的公钥(7EA0A9C3F273FCD8)添加到你的系统中:
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
更新报错
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# sudo apt-get update
Get:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease [48.5 kB]
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease
Err:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease
Hit:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
W: GPG error: https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
E: The repository 'https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker#
E: The repository 'https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease' is not signed.
添加 Docker 官方 GPG 密钥
c
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
添加 Docker 官方软件源
c
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
更新软件包索引并安装
c
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
它最省心。安装完成后,别忘了将你的用户添加到 docker 组,这样就可以不用每次都输入 sudo 了:
c
sudo usermod -aG docker $USER
c
root@wqbboy-VirtualBox:/home/wqbboy# docker -v
Docker version 29.6.2, build dfc4efb
root@wqbboy-VirtualBox:/home/wqbboy# docker compose up -d
no configuration file provided: not found
root@wqbboy-VirtualBox:/home/wqbboy#
现在你遇到的新报错 no configuration file provided: not found 是因为你当前所在的目录不对。
docker compose 命令默认会在你当前所在的文件夹里寻找名为 docker-compose.yml 或 compose.yml 的配置文件。你当前在 /home/wqbboy 目录下,而根据你之前的操作,Dify 的配置文件应该在 /home/wqbboy/difyinstall/dify/docker 目录下45。
🚀 解决步骤
只需要切换回正确的目录,然后再启动即可。请依次运行以下命令:
c
# 1. 切换到 Dify 的 docker 目录
cd /home/wqbboy/difyinstall/dify/docker
# 2. 确认目录下有配置文件(可选)
ls docker-compose.yml
# 3. 再次启动 Dify
docker compose up -d
成功拉起镜像,但报错
c
docker compose up -d
ls: cannot access 'docker-compose.yml': No such file or directory
[+] up 14/74
⠦ Image redis:6-alpine [⣿⣿⣿⠀⠀⣿⠀⣿⣿] Pulling 89.4s
⠦ Image langgenius/dify-api:1.16.0 Pulling 89.4s
⠦ Image busybox:latest [⠀] Pulling 89.4s
⠦ Image langgenius/dify-agent-local-sandbox:1.16.0 Pulling 89.4s
⠦ Image langgenius/dify-web:1.16.0 [⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀] Pulling 89.4s
⠦ Image nginx:latest [⣿⣿⣿⣀⡀⣿⣿⣿⣿] 17.83MB / 65.92MB Pulling 89.4s
⠦ Image langgenius/dify-plugin-daemon:0.6.3-local [⠀⠀⠀⠀⠀] Pulling 89.4s
⠦ Image postgres:15-alpine [⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀] Pulling 89.4s
⠦ Image langgenius/dify-agent-backend:1.16.0 [⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀] Pulling 89.4s
⠦ Image ubuntu/squid:latest [⠀⠀⠀] Pulling 89.4s
⠦ Image semitechnologies/weaviate:1.27.0 [⣿] Pulling 89.4s
⠦ Image langgenius/dify-sandbox:0.2.15 Pulling 89.4s
error from registry: 免费节点当前繁忙,请稍后重试。
如果需要稳定高速的镜像拉取服务,可使用轩辕镜像专业版:
• 专属节点
• 更高稳定性
• 高并发保障
国内镜像源配置
c
#非常重要,编辑daemon.json时,格式问题很难看出来,可以用这个网站来生成格式https://tool.hiofd.com/json-format-online/
#下面是daemon.json的内容,
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://2a6bf1988cb6428c877f723ec7530dbc.mirror.swr.myhuaweicloud.com",
"https://docker.m.daocloud.io",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://your_preferred_mirror",
"https://dockerhub.icu",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc"
]
}
EOF
接着重启 Docker 服务使配置生效:
c
sudo systemctl daemon-reload
sudo systemctl restart docker
c
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# sudo systemctl daemon-reload
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# sudo systemctl restart docker
root@wqbboy-VirtualBox:/home/wqbboy/difyinstall/dify/docker# docker compose up -d
[+] up 52/113
⠋ Image langgenius/dify-api:1.16.0 [⣿⡀⡀⣿⣿⠀⣿⣿⣀⣿⣿⣿⣿⣤⣿] Pulling 68.5s
⠋ Image langgenius/dify-web:1.16.0 [⣿⣿⣿⣿⣀⣿⣿⣿⣿⣿⣿⣿⡀⣀⣿] Pulling 68.5s
⠋ Image langgenius/dify-plugin-daemon:0.6.3-local [⣤⡀⣿⠀⣄] Pulling 68.5s
⠋ Image nginx:latest [⠀⠀⠀⠀⠀⠀⠀] Pulling 68.5s
⠋ Image langgenius/dify-sandbox:0.2.15 [⣤⣿⣶⣦⣿⣿⣿⣿⣿⣿⣿⣄⣿⣿⣿] Pulling 68.5s
⠋ Image postgres:15-alpine [⣿⣿⣿⣦⣿⣿⣿⣿⣿⣿⣿⣿⣿] Pulling 68.5s
⠋ Image langgenius/dify-agent-local-sandbox:1... [⣿⣿⣀⣿⣤⣿⣿⣦⣿⠀⣀⣿⣿⣿] Pulling 68.5s
✔ Image redis:6-alpine Pulled 50.9s
⠋ Image semitechnologies/weaviate:1.27.0 [⠀⠀⠀⠀⠀⠀⠀] Pulling 68.5s
⠋ Image ubuntu/squid:latest [⣿⡀⠀] Pulling 68.5s
✔ Image busybox:latest Pulled 15.7s
⠋ Image langgenius/dify-agent-backend:1.16.0 [⣿⣿⣀⣿⣿⣿⣤⣿⣿⠀⣿] Pulling 68.5s
重新启动 Dify
切换回 Dify 的目录,再次启动:
c
cd /home/wqbboy/difyinstall/dify/docker
docker compose up -d
运行后,可以在浏览器上访问 http://localhost/install 进入 Dify 控制台并开始初始化安装操作
五、接入模型
url: http://*****:11434(若不行,打开终端执行ifconfig,查看本地网络ip,把172.19.0.1进行替换)