fix(batch): resolve container IDs in sub-workflows

When batch operations are triggered via keyboard callbacks, the main
workflow only passes container names (not IDs). The sub-workflows now:
- Check if containerId is empty
- If empty, query Docker API to resolve name → ID
- Then proceed with the action

This fixes batch start/stop/restart/update operations failing with
404 "page not found" errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Lucas Berger
2026-02-04 16:19:33 -05:00
parent f7859fc3c4
commit adbd7bd87d
2 changed files with 209 additions and 11 deletions
+99
View File
@@ -39,6 +39,65 @@
300
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"typeValidation": "loose"
},
"conditions": [
{
"id": "has-container-id",
"leftValue": "={{ $json.containerId }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEquals"
}
}
],
"combinator": "and"
}
},
"id": "if-has-id",
"name": "Has Container ID?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
400,
300
]
},
{
"parameters": {
"url": "http://docker-socket-proxy:2375/v1.47/containers/json?all=true",
"options": {
"timeout": 5000
}
},
"id": "http-get-containers",
"name": "Get All Containers",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
560,
400
]
},
{
"parameters": {
"jsCode": "// Find container by name and resolve ID\nconst triggerData = $('When executed by another workflow').item.json;\nconst containerName = triggerData.containerName;\nconst containers = $input.all();\n\n// Normalize function to strip leading slash\nconst normalizeName = (name) => name.replace(/^\\//, '').toLowerCase();\nconst searchName = normalizeName(containerName);\n\n// Find matching container\nlet matched = null;\nfor (const item of containers) {\n const c = item.json;\n if (c.Names && c.Names.length > 0) {\n const cName = normalizeName(c.Names[0]);\n if (cName === searchName || cName.includes(searchName)) {\n matched = c;\n break;\n }\n }\n}\n\nif (!matched) {\n throw new Error(`Container '${containerName}' not found`);\n}\n\nreturn {\n json: {\n ...triggerData,\n containerId: matched.Id\n }\n};"
},
"id": "code-resolve-id",
"name": "Resolve Container ID",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
400
]
},
{
"parameters": {
"method": "GET",
@@ -616,6 +675,46 @@
],
"connections": {
"When executed by another workflow": {
"main": [
[
{
"node": "Has Container ID?",
"type": "main",
"index": 0
}
]
]
},
"Has Container ID?": {
"main": [
[
{
"node": "Inspect Container",
"type": "main",
"index": 0
}
],
[
{
"node": "Get All Containers",
"type": "main",
"index": 0
}
]
]
},
"Get All Containers": {
"main": [
[
{
"node": "Resolve Container ID",
"type": "main",
"index": 0
}
]
]
},
"Resolve Container ID": {
"main": [
[
{