From 590dc087ac83acf7a1a2711abc086e9aeedb6fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romuald=20Cz=C5=82onkowski?= <56956555+czlonkowski@users.noreply.github.com> Date: Sat, 25 Oct 2025 23:56:54 +0200 Subject: [PATCH] fix: resolve Docker port configuration mismatch (Issue #228) (#373) --- CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 4 ++-- docker-compose.buildkit.yml | 6 +++--- docker-compose.n8n.yml | 5 +++-- docker-compose.yml | 4 ++-- docs/INSTALLATION.md | 6 +++--- package.json | 2 +- 7 files changed, 46 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 427e302..a9bcd99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.22.6] - 2025-10-25 + +### 🐛 Bug Fixes + +**Issue #228: Fix Docker Port Configuration Mismatch** + +Fixed critical Docker configuration bug where custom PORT environment variable values were not properly mapped to container ports, causing connection failures in Docker deployments. + +#### Problem +- **docker-compose.yml**: Port mapping `"${PORT:-3000}:3000"` hardcoded container port to 3000 +- **docker-compose.yml**: Health check hardcoded to port 3000 +- **Dockerfile**: Health check hardcoded to port 3000 +- Impact: When PORT≠3000 (e.g., PORT=8080), Docker mapped host port to wrong container port + +#### Solution +- **docker-compose.yml line 44**: Changed port mapping to `"${PORT:-3000}:${PORT:-3000}"` +- **docker-compose.yml line 56**: Updated health check to use dynamic port `$${PORT:-3000}` +- **Dockerfile line 93**: Updated HEALTHCHECK to use dynamic port `${PORT:-3000}` +- **Dockerfile line 85**: Added clarifying comment about PORT configurability + +#### Testing +- Verified with default PORT (3000) +- Verified with custom PORT (8080) +- Health checks work correctly in both scenarios + +#### Related Issues +- Fixes #228 (Docker Compose port error) +- Likely fixes #109 (Configuration ignored in HTTP mode) +- Likely fixes #84 (Can't access container) + +Conceived by Romuald Członkowski - [www.aiadvisors.pl/en](https://www.aiadvisors.pl/en) + ## [2.22.3] - 2025-10-25 ### 🔧 Code Quality Improvements diff --git a/Dockerfile b/Dockerfile index dcb9eab..bfd4787 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,7 +82,7 @@ ENV IS_DOCKER=true # To opt-out, uncomment the following line: # ENV N8N_MCP_TELEMETRY_DISABLED=true -# Expose HTTP port +# Expose HTTP port (default 3000, configurable via PORT environment variable at runtime) EXPOSE 3000 # Set stop signal to SIGTERM (default, but explicit is better) @@ -90,7 +90,7 @@ STOPSIGNAL SIGTERM # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD curl -f http://127.0.0.1:3000/health || exit 1 + CMD sh -c 'curl -f http://127.0.0.1:${PORT:-3000}/health || exit 1' # Optimized entrypoint ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/docker-compose.buildkit.yml b/docker-compose.buildkit.yml index cc052ef..a5af5be 100644 --- a/docker-compose.buildkit.yml +++ b/docker-compose.buildkit.yml @@ -20,19 +20,19 @@ services: image: n8n-mcp:latest container_name: n8n-mcp ports: - - "3000:3000" + - "${PORT:-3000}:${PORT:-3000}" environment: - MCP_MODE=${MCP_MODE:-http} - AUTH_TOKEN=${AUTH_TOKEN} - NODE_ENV=${NODE_ENV:-production} - LOG_LEVEL=${LOG_LEVEL:-info} - - PORT=3000 + - PORT=${PORT:-3000} volumes: # Mount data directory for persistence - ./data:/app/data restart: unless-stopped healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + test: ["CMD", "sh", "-c", "curl -f http://localhost:$${PORT:-3000}/health"] interval: 30s timeout: 10s retries: 3 diff --git a/docker-compose.n8n.yml b/docker-compose.n8n.yml index babffab..19dfa5d 100644 --- a/docker-compose.n8n.yml +++ b/docker-compose.n8n.yml @@ -37,11 +37,12 @@ services: container_name: n8n-mcp restart: unless-stopped ports: - - "${MCP_PORT:-3000}:3000" + - "${MCP_PORT:-3000}:${MCP_PORT:-3000}" environment: - NODE_ENV=production - N8N_MODE=true - MCP_MODE=http + - PORT=${MCP_PORT:-3000} - N8N_API_URL=http://n8n:5678 - N8N_API_KEY=${N8N_API_KEY} - MCP_AUTH_TOKEN=${MCP_AUTH_TOKEN} @@ -56,7 +57,7 @@ services: n8n: condition: service_healthy healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + test: ["CMD", "sh", "-c", "curl -f http://localhost:$${MCP_PORT:-3000}/health"] interval: 30s timeout: 10s retries: 3 diff --git a/docker-compose.yml b/docker-compose.yml index b4fe7a5..f6e1d2a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: # Port mapping ports: - - "${PORT:-3000}:3000" + - "${PORT:-3000}:${PORT:-3000}" # Resource limits deploy: @@ -53,7 +53,7 @@ services: # Health check healthcheck: - test: ["CMD", "curl", "-f", "http://127.0.0.1:3000/health"] + test: ["CMD", "sh", "-c", "curl -f http://127.0.0.1:$${PORT:-3000}/health"] interval: 30s timeout: 10s retries: 3 diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index 80074b1..3dd29ca 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -59,10 +59,10 @@ docker compose up -d - n8n-mcp-data:/app/data ports: - - "${PORT:-3000}:3000" - + - "${PORT:-3000}:${PORT:-3000}" + healthcheck: - test: ["CMD", "curl", "-f", "http://127.0.0.1:3000/health"] + test: ["CMD", "sh", "-c", "curl -f http://127.0.0.1:$${PORT:-3000}/health"] interval: 30s timeout: 10s retries: 3 diff --git a/package.json b/package.json index 1b003a8..a4966da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "n8n-mcp", - "version": "2.22.5", + "version": "2.22.6", "description": "Integration between n8n workflow automation and Model Context Protocol (MCP)", "main": "dist/index.js", "types": "dist/index.d.ts",