解决方案:构建一个带有python环境的镜像
1.写一个docker-compose.yml,中文部分改成你自己的
services:
n8n:
build: .
image: n8nio/n8n:latest
container_name: n8n
restart: always
ports:
- "5678:5678"
- "5679:5679"
environment:
- TZ=Asia/Shanghai
- GENERIC_TIMEZONE=Asia/Shanghai
- N8N_HOST=你的IP
- N8N_PORT=5678
- N8N_PROTOCOL=http
- WEBHOOK_URL=http://你的IP:5678/
- N8N_SECURE_COOKIE=false
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=你的密码
- N8N_RUNNERS_ENABLED=true
- N8N_RUNNERS_MODE=external
- N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
- N8N_RUNNERS_AUTH_TOKEN=my-runner-token
- N8N_RUNNERS_EXTERNAL_ALLOW=*
volumes:
- 你的路径:/home/node/.n8n
runner:
image: n8nio/runners:latest
container_name: n8n-runner
restart: always
environment:
- N8N_RUNNERS_TASK_BROKER_URI=http://n8n:5679
- N8N_RUNNERS_AUTH_TOKEN=my-runner-token
depends_on:
- n8n
2.写一个Dockerfile
FROM n8nio/runners:latest
USER root
RUN pip install pandas requests numpy
3.在Dockerfile里面添加你要的包
4.更新
docker compose down
docker compose up -d
5.验证python能不能用
进入命令行自己验证,也可以pip安装,测试过了
docker exec -it n8n-runner sh