hello,friends,I’m new here.
I use the external mode run n8n,
when run “docker-compose up -d”,
everything is ok,
but when I make a workflow which contain a python code node,
then code:
import socket
return [{
“hostname”: socket.gethostname(),
“message”: f"Running in container: {socket.gethostname()}",
“success”: True
}]
output:
1 item
[
{
“hostname”:
“emscripten”,
“message”:
“Running in container: emscripten”,
“success”:
true
}
]
however,the task runners container hostname is: server_n8n_runners
It really make me confused!
when execute:
docker-compose exec n8n curl -H “Authorization: Bearer test” http://localhost:5678/rest/settings?keys=executionMode
I find ---- “executionMode”:“regular”,
AI answers this should be “queue”,
but the n8n webs can’t modify the “executionMode”,
hope some exprienced friend could work my quetions out ,thanks!
below is my yaml config file:
version: '3.8'
volumes:
db_storage:
driver_opts:
type: none
o: bind
device: /home/docker/pgsql17/db_data # 宿主机上的绝对路径
n8n_storage:
driver_opts:
type: none
o: bind
device: /home/docker/n8n_runner_mode/n8n_home # 宿主机上的另一个绝对路径
services:
postgres:
image: postgres:17
restart: always
container_name: pg17
hostname: server_pg17
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
- POSTGRES_NON_ROOT_USER
- POSTGRES_NON_ROOT_PASSWORD
- TZ=Asia/Shanghai # 设置时区环境变量
ports:
- 5432:5432
volumes:
- db_storage:/var/lib/postgresql/data
- /home/docker/pgsql17/db_backup:/backups
- ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
- ./apt_source.conf:/etc/apt/sources.list.d/pgdg.list
- ./pip.conf:/etc/pip.conf
- ./uv.toml:/home/root/.config/uv/uv.toml
- /etc/localtime:/etc/localtime:ro # 挂载宿主机时区文件
- /etc/timezone:/etc/timezone:ro # 挂载宿主机时区配置
healthcheck:
test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
interval: 5s
timeout: 5s
retries: 10
networks:
- n8n_net
n8n:
image: n8nio/n8n:1.113.3
restart: always
container_name: n8n_main
hostname: server_n8n_main
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- N8N_RUNNERS_ENABLED=true
- N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
- N8N_RUNNERS_MODE=external # 关键:设置为外部模式
- N8N_RUNNERS_AUTH_TOKEN=test
- N8N_LOG_LEVEL=debug
- N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true
- N8N_SECURE_COOKIE=false
- N8N_BLOCK_ENV_ACCESS_IN_NODE=false
- N8N_GIT_NODE_DISABLE_BARE_REPOS=true
- TZ=Asia/Shanghai # 设置时区环境变量
- N8N_TIMEZONE=Asia/Shanghai
- GENERIC_TIMEZONE=Asia/Shanghai
ports:
- 5678:5678
expose:
- "5679"
volumes:
- n8n_storage:/home/node/.n8n
- /home/docker/n8n_runner_mode/n8n_data:/data
- ./repositories:/etc/apk/repositories
- ./pip.conf:/etc/pip.conf
- ./uv.toml:/root/.config/uv/uv.toml
- /etc/localtime:/etc/localtime:ro # 挂载宿主机时区文件
- /etc/timezone:/etc/timezone:ro # 挂载宿主机时区配置
depends_on:
- postgres
networks:
- n8n_net
task_runners:
image: n8nio/runners:1.113.3
restart: always
container_name: n8n_runners
hostname: server_n8n_runners
environment:
- N8N_RUNNERS_AUTH_TOKEN=test
- N8N_RUNNERS_TASK_BROKER_URI=http://n8n_main:5679
- NODE_FUNCTION_ALLOW_BUILTIN=*
- NODE_FUNCTION_ALLOW_EXTERNAL=*
- N8N_RUNNERS_STDLIB_ALLOW=*
- N8N_RUNNERS_EXTERNAL_ALLOW=*
- N8N_RUNNERS_LAUNCHER_LOG_LEVEL=debug
- TZ=Asia/Shanghai # 设置时区环境变量
volumes:
- /etc/localtime:/etc/localtime:ro # 挂载宿主机时区文件
- /etc/timezone:/etc/timezone:ro # 挂载宿主机时区配置
- ./repositories:/etc/apk/repositories
- ./pip.conf:/etc/pip.conf
- ./uv.toml:/home/runner/.config/uv/uv.toml
expose:
- "5680"
depends_on:
- n8n
networks:
- n8n_net
networks:
n8n_net:
driver: bridge