{"record":{"id":"614895ccf4c4adb5","repo":"Dokploy/dokploy","slug":"conflict-614895","errorCode":"CONFLICT","errorMessage":"Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}","messagePattern":"Port (.+?) is already in use by (.+?)","errorType":"exception","errorClass":"TRPCError","httpStatus":409,"severity":"error","filePath":"apps/dokploy/server/api/routers/postgres.ts","lineNumber":209,"sourceCode":"\t\t\t\tresourceName: postgres.appName,\n\t\t\t});\n\t\t\treturn postgres;\n\t\t}),\n\tsaveExternalPort: protectedProcedure\n\t\t.input(apiSaveExternalPortPostgres)\n\t\t.mutation(async ({ input, ctx }) => {\n\t\t\tawait checkServicePermissionAndAccess(ctx, input.postgresId, {\n\t\t\t\tservice: [\"create\"],\n\t\t\t});\n\t\t\tconst postgres = await findPostgresById(input.postgresId);\n\n\t\t\tif (input.externalPort) {\n\t\t\t\tconst portCheck = await checkPortInUse(\n\t\t\t\t\tinput.externalPort,\n\t\t\t\t\tpostgres.serverId || undefined,\n\t\t\t\t);\n\t\t\t\tif (portCheck.isInUse) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: \"CONFLICT\",\n\t\t\t\t\t\tmessage: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tawait updatePostgresById(input.postgresId, {\n\t\t\t\texternalPort: input.externalPort,\n\t\t\t});\n\t\t\tawait deployPostgres(input.postgresId);\n\t\t\tawait audit(ctx, {\n\t\t\t\taction: \"update\",\n\t\t\t\tresourceType: \"service\",\n\t\t\t\tresourceId: postgres.postgresId,\n\t\t\t\tresourceName: postgres.appName,\n\t\t\t});\n\t\t\treturn postgres;\n\t\t}),","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/postgres.ts#L191-L227","documentation":"CONFLICT thrown during postgres update when input.externalPort is set and checkServiceSettingsPort/checkPortInUse detects another container already bound to that host port (optionally on a specific server). Docker cannot bind two containers to the same host port.","triggerScenarios":"Updating a Postgres to an externalPort already published by another container (conflictingContainer name is included in the message); also triggers if the port is used outside Docker on the selected server.","commonSituations":"Reusing a port exposed by another database/app; moving a Postgres to a server where the port is taken; port value left over from a copied config.","solutions":["Choose a different externalPort not listed as in use","Stop or reconfigure the conflicting container named in the message","If the conflict is with the same Postgres's old deployment, ensure the old container is fully removed before changing the port"],"exampleFix":"// before\nawait api.postgres.update.mutate({ postgresId, externalPort: 5432 });\n// after\nawait api.postgres.update.mutate({ postgresId, externalPort: 5433 });","handlingStrategy":"validation","validationCode":"const check = await checkPortInUse(externalPort, serverId);\nif (check.isInUse) throw new Error(`Port taken by ${check.conflictingContainer}`);","typeGuard":null,"tryCatchPattern":"catch (e) { if (e.data?.code === 'CONFLICT') autoIncrementPortAndRetry(); }","preventionTips":["Let Dokploy auto-assign ports when possible","Maintain a port registry per server to avoid collisions"],"tags":["dokploy","port-conflict","docker","postgres"],"backgroundTag":"port-already-in-use","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}