安装私有节点#
您可以构建自己的节点并将其安装到 n8n 实例中,而无需将其发布到 npm。这对于仅为公司内部使用而创建的节点非常有用。
在 Docker n8n 实例中安装节点#
若通过 Docker 运行 n8n,您需要创建一个已安装该节点的 Docker 镜像。
-
创建 Dockerfile 并粘贴此 Dockerfile 中的代码。
您的 Dockerfile 应如下所示:
FROM node:16-alpine
ARG N8N_VERSION
RUN if [ -z "$N8N_VERSION" ] ; then echo "The N8N_VERSION argument is missing!" ; exit 1; fi
# Update everything and install needed dependencies
RUN apk add --update graphicsmagick tzdata git tini su-exec
# Set a custom user to not have n8n run as root
USER root
# Install n8n and the packages it needs to build it correctly.
RUN apk --update add --virtual build-dependencies python3 build-base ca-certificates && \
npm config set python "$(which python3)" && \
npm_config_user=root npm install -g full-icu n8n@${N8N_VERSION} && \
apk del build-dependencies \
&& rm -rf /root /tmp/* /var/cache/apk/* && mkdir /root;
# Install fonts
RUN apk --no-cache add --virtual fonts msttcorefonts-installer fontconfig && \
update-ms-fonts && \
fc-cache -f && \
apk del fonts && \
find /usr/share/fonts/truetype/msttcorefonts/ -type l -exec unlink {} \; \
&& rm -rf /root /tmp/* /var/cache/apk/* && mkdir /root
ENV NODE_ICU_DATA /usr/local/lib/node_modules/full-icu
WORKDIR /data
COPY docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
EXPOSE 5678/tcp
- 编译您的自定义节点代码(若使用 nodes starter 则执行
npm run build)。从 dist 文件夹内复制 node 与 credential 文件夹至容器的~/.n8n/custom/目录,使其在 Docker 环境中可用。 - 下载 docker-entrypoint.sh 文件,并将其放置在与 Dockerfile 相同的目录中。
- 构建 Docker 镜像:
# Replace <n8n-version-number> with the n8n release version number.
# For example, N8N_VERSION=0.177.0
docker build --build-arg N8N_VERSION=<n8n-version-number> --tag=customizedn8n .
现在您可以在Docker中使用您的节点了。
在全局n8n实例中安装您的节点#
如果您已全局安装n8n,请确保在n8n内部安装您的节点。n8n将自动找到该模块并加载它。