{"record":{"id":"b3bc4bea7df2c1bb","repo":"nextcloud/all-in-one","slug":"could-not-create-container-identifier-details","errorCode":null,"errorMessage":"Could not create container {identifier}: {details}","messagePattern":"Could not create container (.+?): (.+?)","errorType":"exception","errorClass":"\\Exception","httpStatus":500,"severity":"critical","filePath":"php/src/Docker/DockerActionManager.php","lineNumber":517,"sourceCode":"        // Also DIUN should not send update notifications. See https://crazymax.dev/diun/providers/docker/#docker-labels\n        // Also Dockhand should not be auto updating the containers. See https://dockhand.pro/manual/#container-labels-behavior\n        // Additionally set a default org.label-schema.vendor and com.docker.compose.project\n        $requestBody['Labels'] = [\"com.centurylinklabs.watchtower.enable\" => \"false\", \"wud.watch\" => \"false\", \"diun.enable\" => \"false\", \"dockhand.update\" => \"false\", \"org.label-schema.vendor\" => \"Nextcloud\", \"com.docker.compose.project\" => \"nextcloud-aio\"];\n\n        // Containers should have a fixed host name. See https://github.com/nextcloud/all-in-one/discussions/6589\n        $requestBody['Hostname'] = $container->identifier;\n\n        $url = $this->BuildApiUrl('containers/create?name=' . $container->identifier);\n        try {\n            $this->sendHttpRequest(\n                'POST',\n                $url,\n                [\n                    'json' => $requestBody\n                ]\n            );\n        } catch (RequestException $e) {\n            throw new \\Exception(\"Could not create container \" . $container->identifier . \": \" . $e->getResponse()?->getBody()->getContents());\n        }\n\n    }\n\n    public function isRegistryReachable(Container $container): bool {\n        $tag = $container->imageTag;\n        if ($tag === '%AIO_CHANNEL%') {\n            $tag = $this->GetCurrentChannel();\n        }\n\n        $remoteDigest = $this->GetLatestDigestOfTag($container->containerName, $tag);\n\n        if ($remoteDigest === null) {\n            return false;\n        } else {\n            return true;\n        }\n    }","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/nextcloud/all-in-one/blob/6b788eec5e61733cf03ed380a3572e43ae3f11ce/php/src/Docker/DockerActionManager.php#L499-L535","documentation":"POST /containers/create?name={identifier} returned an error; the daemon's message body is embedded. Typical daemon replies: 409 'Conflict. The container name \"...\" is already in use' (names are unique across running AND stopped containers) and 400 for invalid volume, port, or request-body specs.","triggerScenarios":"A container with the same name already exists (running or stopped/exited); duplicate host-port bindings in the request; a referenced volume, network, or image that is invalid or missing.","commonSituations":"Re-running AIO setup without removing the previous container; stale containers left after a failed update; editing a container's config while the old one still exists.","solutions":["Find the conflict: docker ps -a | grep <identifier>, then docker rm the stale container and retry","If ports conflict, stop the container holding them or change the bindings","Validate the request body (volumes, port mappings) against the Docker Engine API version in use","As a last resort clean up all AIO containers: docker rm -f $(docker ps -aq --filter name=nextcloud-aio)"],"exampleFix":"// before: create directly, fail on stale name\n$docker->CreateContainer($container);\n// after: remove a stopped stale container with the same name first\n$existing = $docker->sendHttpRequest('GET', $docker->BuildApiUrl('containers/json?all=1'));\nforeach (json_decode($existing->getBody(), true) as $c) {\n    if (in_array('/' . $container->identifier, $c['Names'], true) && $c['State'] !== 'running') {\n        $docker->sendHttpRequest('DELETE', $docker->BuildApiUrl('containers/' . $c['Id']));\n    }\n}\n$docker->CreateContainer($container);","handlingStrategy":"validation","validationCode":"// Detect and remove a stopped stale container with the same name before creating\n$list = json_decode($docker->sendHttpRequest('GET', $docker->BuildApiUrl('containers/json?all=1'))->getBody(), true) ?: [];\nforeach ($list as $c) {\n    if (in_array('/' . $container->identifier, $c['Names'], true) && ($c['State'] ?? '') !== 'running') {\n        $docker->sendHttpRequest('DELETE', $docker->BuildApiUrl('containers/' . $c['Id']));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $docker->CreateContainer($container);\n} catch (\\Exception $e) {\n    if (str_contains($e->getMessage(), 'name') && str_contains($e->getMessage(), 'already in use')) {\n        removeStaleContainer($container->identifier);\n        return $docker->CreateContainer($container); // exactly one recovery retry\n    }\n    throw $e;\n}","preventionTips":["Container names are unique across running AND stopped containers — always remove-then-create in setup scripts","Delete (docker rm) before recreate; never assume a stopped container is harmless","Validate port mappings and volume names before sending the create request (400s come from bad specs)"],"tags":["php","docker","containers","name-conflict","daemon-api"],"backgroundTag":"docker-container-create-failed","analyzedSha":"6b788eec5e61733cf03ed380a3572e43ae3f11ce","analyzedAt":"2026-08-21T05:47:24.382Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}