Docker Compose(Docker-Compose)#
这些说明介绍了如何使用 Docker Compose 在 Linux 服务器上运行 n8n。
🌐 These instructions cover how to run n8n on a Linux server using Docker Compose.
如果你已经安装了 Docker 和 Docker-Compose,那么你可以从 第3步 开始。
🌐 If you have already installed Docker and Docker-Compose, then you can start with step 3.
你可以在 n8n-hosting 仓库 中找到适用于各种架构的 Docker Compose 配置。
🌐 You can find Docker Compose configurations for various architectures in the n8n-hosting repository.
Self-hosting knowledge prerequisites
Self-hosting n8n requires technical knowledge, including:
- Setting up and configuring servers and containers
- Managing application resources and scaling
- Securing servers and applications
- Configuring n8n
n8n recommends self-hosting for expert users. Mistakes can lead to data loss, security issues, and downtime. If you aren't experienced at managing servers, n8n recommends n8n Cloud.
Stable and Beta versions
n8n releases a new minor version most weeks. The stable version is for production use. beta is the most recent release. The beta version may be unstable. To report issues, use the forum.
Current stable: 2.4.7
Current beta: 2.6.2
1. 安装 Docker 和 Docker Compose(1. Install Docker and Docker Compose)#
安装 Docker 和 Docker Compose 的方式取决于你的 Linux 发行版。你可以在下面的链接中找到每个组件的具体说明:
🌐 The way that you install Docker and Docker Compose depends on your Linux distribution. You can find specific instructions for each component in the links below:
按照安装说明操作后,输入以下命令验证 Docker 和 Docker Compose 是否可用:
🌐 After following the installation instructions, verify that Docker and Docker Compose are available by typing:
1 2 | |
2. 可选:非 root 用户访问(2. Optional: Non-root user access)#
您可以选择授予访问权限,以便在不使用 sudo 命令的情况下运行 Docker。
🌐 You can optionally grant access to run Docker without the sudo command.
要授予你当前登录的用户访问权限(假设他们拥有 sudo 访问权限),请运行:
🌐 To grant access to the user that you're currently logged in with (assuming they have sudo access), run:
1 2 3 | |
要授予其他用户访问权限,请输入以下内容,并将 <USER_TO_RUN_DOCKER> 替换为相应的用户名:
🌐 To grant access to a different user, type the following, substituting <USER_TO_RUN_DOCKER> with the appropriate username:
1 | |
你需要在该用户的任何现有会话中运行 exec sg docker newgrp,才能使其访问新的组权限。
🌐 You will need to run exec sg docker newgrp from any of that user's existing sessions for it to access the new group permissions.
您可以通过输入以下命令来验证当前会话是否识别 docker 组:
🌐 You can verify that your current session recognizes the docker group by typing:
1 | |
3. DNS 设置(3. DNS setup)#
要在线或通过网络托管 n8n,请创建一个指向你服务器的专用子域名。
🌐 To host n8n online or on a network, create a dedicated subdomain pointed at your server.
添加一条 A 记录,以便相应地路由子域名:
🌐 Add an A record to route the subdomain accordingly:
| 记录类型 | 名称 | 目标地址 |
|---|---|---|
| A | n8n(或您想要的子域名) |
<your_server_IP_address> |
4. 创建一个 .env 文件(4. Create an .env file)#
创建一个项目目录来存储你的 n8n 环境配置和 Docker Compose 文件,并导航到该目录:
🌐 Create a project directory to store your n8n environment configuration and Docker Compose files and navigate inside:
1 2 | |
在 n8n-compose 目录下,创建一个 .env 文件来自定义你的 n8n 实例的详细信息。将其修改为与你自己的信息相符:
🌐 Inside the n8n-compose directory, create an .env file to customize your n8n instance's details. Change it to match your own information:
| .env file | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
5. 创建本地文件目录(5. Create local files directory)#
在你的项目目录中,创建一个名为 local-files 的目录,用于在 n8n 实例和主机系统之间共享文件(例如,使用 从磁盘读取/写入文件节点):
🌐 Inside your project directory, create a directory called local-files for sharing files between the n8n instance and the host system (for example, using the Read/Write Files from Disk node):
1 | |
下面的 Docker Compose 文件可以自动创建此目录,但手动创建可确保其具有正确的所有权和权限。
🌐 The Docker Compose file below can automatically create this directory, but doing it manually ensures that it's created with the right ownership and permissions.
6. 创建 Docker Compose 文件(6. Create Docker Compose file)#
创建一个 compose.yaml 文件。在文件中粘贴以下内容:
🌐 Create a compose.yaml file. Paste the following in the file:
| compose.yaml file | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
上面的 Docker Compose 文件配置了两个容器:一个用于 n8n,另一个用于运行 traefik,这是一个应用代理,用于管理 TLS/SSL 证书并处理路由。
🌐 The Docker Compose file above configures two containers: one for n8n, and one to run traefik, an application proxy to manage TLS/SSL certificates and handle routing.
它还会创建并挂载两个 Docker 卷,并挂载你之前创建的 local-files 目录:
🌐 It also creates and mounts two Docker Volumes and mounts the local-files directory you created earlier:
| 名称 | 类型 | 容器挂载 | 描述 |
|---|---|---|---|
n8n_data |
卷 | /home/node/.n8n |
n8n 保存其 SQLite 数据库文件和加密密钥的地方。 |
traefik_data |
卷 | /letsencrypt |
traefik 保存 TLS/SSL 证书数据的地方。 |
./local-files |
绑定 | /files |
n8n 实例与主机之间共享的本地目录。在 n8n 中,使用 /files 路径读取和写入该目录。 |
7. 启动 Docker Compose(7. Start Docker Compose)#
输入以下内容启动 n8n:
🌐 Start n8n by typing:
1 | |
要停止容器,请键入:
🌐 To stop the containers, type:
1 | |
8. 完成(8. Done)#
现在,您可以使用在 .env 文件配置中定义的子域名 + 域名组合访问 n8n。上述示例将得到 https://n8n.example.com。
🌐 You can now reach n8n using the subdomain + domain combination you defined in your .env file configuration. The above example would result in https://n8n.example.com.
n8n 仅支持通过安全的 HTTPS 访问,不支持普通的 HTTP 访问。
🌐 n8n is only accessible using secure HTTPS, not over plain HTTP.
如果你无法访问实例,请检查服务器的防火墙设置和 DNS 配置。
🌐 If you have trouble reaching your instance, check your server's firewall settings and your DNS configuration.
下一步步骤(Next steps)#
- Learn more about configuring and scaling n8n.
- Or explore using n8n: try the Quickstarts.