{"record":{"id":"a33fc8ea1d40f1f1","repo":"coollabsio/coolify","slug":"invalid-container-name-contains-forbidden-charact","errorCode":null,"errorMessage":"Invalid container name: contains forbidden characters.","messagePattern":"Invalid container name: contains forbidden characters\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"app/Jobs/ApplicationDeploymentJob.php","lineNumber":4697,"sourceCode":"            throw new \\RuntimeException(\"Invalid {$fieldName}: path traversal detected.\");\n        }\n\n        return $value;\n    }\n\n    private function validateShellSafeCommand(string $value, string $fieldName): string\n    {\n        if (! preg_match(ValidationPatterns::SHELL_SAFE_COMMAND_PATTERN, $value)) {\n            throw new \\RuntimeException(\"Invalid {$fieldName}: contains forbidden shell characters.\");\n        }\n\n        return $value;\n    }\n\n    private function validateContainerName(string $value): string\n    {\n        if (! preg_match(ValidationPatterns::CONTAINER_NAME_PATTERN, $value)) {\n            throw new \\RuntimeException('Invalid container name: contains forbidden characters.');\n        }\n\n        return $value;\n    }\n\n    /**\n     * Resolve which container to execute a deployment command in.\n     *\n     * For single-container apps, returns the sole container.\n     * For multi-container apps, matches by the user-specified container name.\n     * If no container name is specified for multi-container apps, logs available containers and returns null.\n     */\n    private function resolveCommandContainer(Collection $containers, ?string $specifiedContainerName, string $commandType): ?array\n    {\n        if ($containers->count() === 0) {\n            return null;\n        }\n","sourceCodeStart":4679,"sourceCodeEnd":4715,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Jobs/ApplicationDeploymentJob.php#L4679-L4715","documentation":"validateContainerName() checks the value against ValidationPatterns::CONTAINER_NAME_PATTERN (/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/), mirroring Docker's own container naming rules: must start with a letter or digit, then letters, digits, dots, hyphens, underscores. The check runs when a deployment needs to resolve which container to execute commands in; values with spaces, leading -/._, $, or other characters throw.","triggerScenarios":"A user-specified container name field (used to pick a container in multi-container apps) contains e.g. 'my app', '-app', '_app', 'app$1', or trailing whitespace; copy-paste introduced invisible characters or quotes.","commonSituations":"Container names copied from docker ps with extra columns; names derived from service names containing forbidden characters; manually typed names starting with underscore (Docker allows it, this stricter pattern does not).","solutions":["Use a name like 'my-app-1': starts with a letter/digit, then only [a-zA-Z0-9._-].","Trim whitespace and remove quotes/backslashes introduced by copy-paste.","If you store the value via API/UI, validate with ValidationPatterns::containerNameRules() at input time."],"exampleFix":"# before: leading underscore and space\ndockerRunCommandTag/container: '_my app'\n\n# after: pattern-compliant name\ncontainer: 'my-app'","handlingStrategy":"validation","validationCode":"$validated = $request->validate(\n    ['container_name' => ValidationPatterns::containerNameRules()]\n    + ['container_name.regex' => 'Container name must start with a letter or digit and contain only letters, digits, dots, hyphens, underscores.']\n);","typeGuard":"function isValidContainerName(string $name): bool\n{\n    return preg_match(\\App\\Support\\ValidationPatterns::CONTAINER_NAME_PATTERN, trim($name)) === 1;\n}","tryCatchPattern":null,"preventionTips":["Trim whitespace on save; copy-paste often adds stray characters.","Avoid leading underscores/hyphens even though Docker tolerates them — this pattern does not.","Derive container names programmatically from validated service names instead of free-text input."],"tags":["docker","deployment","container-name","validation"],"backgroundTag":"invalid-container-name","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}