fix: improve port conflict detection by enhancing error messages and …#3940
Conversation
…adding host-level service checks
| // Check if port is in use by a host-level service (non-Docker) | ||
| // Dokploy runs inside a container, so we spawn an ephemeral container | ||
| // with --net=host to share the host's network stack and use nc -z to | ||
| // check if something is listening on the port | ||
| const hostCommand = `docker run --rm --net=host busybox sh -c 'nc -z 0.0.0.0 ${port} 2>/dev/null && echo in_use || echo free'`; | ||
| const { stdout: hostOut } = serverId | ||
| ? await execAsyncRemote(serverId, hostCommand) | ||
| : await execAsync(hostCommand); | ||
|
|
||
| if (hostOut.includes("in_use")) { | ||
| return { | ||
| isInUse: true, | ||
| conflictingContainer: "a host-level service", | ||
| }; | ||
| } |
There was a problem hiding this comment.
Host check false-positive against Traefik's own ports
The Docker check explicitly excludes dokploy-traefik via grep -v '^dokploy-traefik$' on line 417, but the subsequent nc -z host-level check has no awareness of this exclusion. If Traefik is already running and listening on a port (e.g., 8080 for the dashboard), the Docker check will skip Traefik and find no container conflict, then the host check will detect the open port and return { isInUse: true, conflictingContainer: "a host-level service" }.
The result is a misleading error message: when a user tries to enable the Traefik dashboard on an already-configured port, they are told the port is occupied by "a host-level service" when the actual occupant is Traefik itself.
Consider checking whether dokploy-traefik is already listening on the target port (e.g., by querying its port mappings) and skipping the host-level check if it is, or unifying the exclusion logic so the host check is also aware of Traefik.
…adding host-level service checks
What is this PR about?
Please describe in a short paragraph what this PR is about.
Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
closes #3806
Screenshots (if applicable)
Greptile Summary
This PR improves port conflict detection in
checkPortInUseby (1) moving the quoted container-name formatting into the return value itself, and (2) adding a second host-level probe via an ephemeraldocker run --rm --net=host busybox nc -zcontainer to catch non-Docker services that may already occupy a port.Key changes:
packages/server/src/services/settings.ts:checkPortInUsenow runs a two-stage check — first Docker containers (excludingdokploy-traefik), then a host-networknc -zprobe for any remaining listeners.apps/dokploy/server/api/routers/settings.ts: Error message construction is updated to match the new string format returned bycheckPortInUse.Issue found:
nc -zprobe does not account fordokploy-traefikbeing excluded from the Docker check. If Traefik itself is already listening on the target port, the probe will misreport it as "a host-level service", producing a misleading conflict error when users try to reconfigure existing Traefik ports.Confidence Score: 3/5
checkPortInUsefunction logic around the Traefik exclusionLast reviewed commit: ce82e23
Context used: