{"record":{"id":"2df22aa05c1d6f48","repo":"microsoft/autogen","slug":"failed-to-start-container-from-image-self-image","errorCode":null,"errorMessage":"Failed to start container from image {self._image}. Logs: {logs_str}","messagePattern":"Failed to start container from image (.+?)\\. Logs: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py","lineNumber":565,"sourceCode":"            working_dir=\"/workspace\",\n            extra_hosts=self._extra_hosts,\n            device_requests=self._device_requests,\n        )\n        await asyncio.to_thread(self._container.start)\n\n        await _wait_for_ready(self._container)\n\n        async def cleanup() -> None:\n            await self.stop()\n            asyncio_atexit.unregister(cleanup)  # type: ignore\n\n        if self._stop_container:\n            asyncio_atexit.register(cleanup)  # type: ignore\n\n        # Check if the container is running\n        if self._container.status != \"running\":\n            logs_str = self._container.logs().decode(\"utf-8\")\n            raise ValueError(f\"Failed to start container from image {self._image}. Logs: {logs_str}\")\n\n        self._loop = asyncio.get_running_loop()\n        self._cancellation_futures = []\n        logging.debug(f\"Executor started, associated with event loop: {self._loop!r}\")\n\n        self._running = True\n\n    def _to_config(self) -> DockerCommandLineCodeExecutorConfig:\n        \"\"\"(Experimental) Convert the component to a config object.\"\"\"\n        if self._functions:\n            logging.info(\"Functions will not be included in serialized configuration\")\n\n        return DockerCommandLineCodeExecutorConfig(\n            image=self._image,\n            container_name=self.container_name,\n            timeout=self._timeout,\n            work_dir=str(self._work_dir) if self._work_dir else None,\n            bind_dir=str(self._bind_dir) if self._bind_dir else None,","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py#L547-L583","documentation":"Raised by DockerCommandLineCodeExecutor.start() after the container is created and _wait_for_ready() returns, but container.status is still not 'running'. The container's own log output is appended so you can see why the entrypoint failed inside the container.","triggerScenarios":"Supplying a custom image whose entrypoint immediately exits (bad command, missing binary), an image that crashes on startup, a container that dies between the readiness wait and the status check, or resource constraints (OOM) killing the container at start.","commonSituations":"Using a minimal image without /bin/sh or the expected sleep entrypoint, images built for a different architecture (exec format error), images whose default CMD exits instantly, Docker daemon out of memory, or stale/broken custom images cached locally.","solutions":["Read the appended container Logs in the exception message - it states the actual container-start failure.","Test the image manually: docker run --rm <image> and confirm it stays up; fix its entrypoint/CMD or use the default python:3-slim image.","Rebuild the custom image (docker build --no-cache ...) in case it is stale or built for the wrong platform (--platform linux/amd64).","If OOM-killed, free memory or raise Docker's memory limits."],"exampleFix":"# before\nexecutor = DockerCommandLineCodeExecutor(image=\"my-custom-executor\")\nawait executor.start()  # ValueError: Failed to start container ... Logs: exec /bin/sh: exec format error\n\n# after\n# rebuild for the host platform and verify it stays running:\n#   docker build --platform linux/amd64 -t my-custom-executor .\n#   docker run --rm -d my-custom-executor sleep 30\nexecutor = DockerCommandLineCodeExecutor(image=\"my-custom-executor\")\nawait executor.start()","handlingStrategy":"try-catch","validationCode":"import docker\n\ndef image_present(image: str) -> bool:\n    try:\n        docker.from_env().images.get(image)\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    await executor.start()\nexcept ValueError as e:\n    if str(e).startswith(\"Failed to start container\"):\n        logs = str(e).split(\"Logs:\", 1)[-1]  # container logs for diagnosis\n        raise RuntimeError(f\"Container image broken, check entrypoint: {logs}\") from e\n    raise","preventionTips":["Smoke-test custom executor images with docker run --rm <image> sleep 5 in CI.","Build images for the host platform explicitly (--platform).","Keep a known-good default image fallback in deployment configs."],"tags":["docker","container","executor","startup"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}