microsoft/autogen · error · ValueError

Failed to obtain container id.

Error message

Failed to obtain container id.

What it means

Defensive check in DockerJupyterServer.__init__ after container creation: container.id came back None from docker-py. In practice this is nearly unreachable (docker-py always populates id on a created container); it guards against SDK/driver anomalies rather than user error.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/docker_jupyter/_jupyter_server.py:384

            auto_remove=auto_remove,
            environment=env,
            publish_all_ports=True,
            name=container_name,
            volumes=volumes,
            working_dir=str(work_dir),
        )

        # Wait for container to be ready
        self._wait_for_ready(container)

        # Store container information
        self._container = container
        self._port = int(container.ports[f"{expose_port}/tcp"][0]["HostPort"])
        self._container_id = container.id
        self._expose_port = expose_port

        if self._container_id is None:
            raise ValueError("Failed to obtain container id.")

        # Define cleanup function
        def cleanup() -> None:
            try:
                assert self._container_id is not None
                inner_container = client.containers.get(self._container_id)
                inner_container.stop()
            except docker.errors.NotFound:
                pass
            atexit.unregister(cleanup)

        # Register cleanup if container should be stopped automatically
        if stop_container:
            atexit.register(cleanup)

        self._cleanup_func = cleanup
        self._stop_container = stop_container

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Upgrade the docker Python package (pip install -U docker) to match your daemon.
  2. If mocking in tests, make the fake container object return a non-None id and status 'running'.
  3. Verify against real Docker with docker version to rule out driver/daemon anomalies.

Example fix

# before (test stub)
fake_container.id = None

# after (test stub)
fake_container.id = "abc123"
fake_container.status = "running"
Defensive patterns

Strategy: try-catch

Try / catch

try:
    server = DockerJupyterServer(...)
except ValueError as e:
    if "Failed to obtain container id" in str(e):
        raise RuntimeError("Docker SDK returned a container without an id; upgrade docker-py") from e
    raise

Prevention

When it happens

Trigger: A docker-py version or Docker API edge case where the container object is returned without an id, e.g. unusual remote Docker drivers, heavily mocked docker clients in tests, or SDK regressions.

Common situations: Unit tests that mock docker.from_env()/containers.run with incomplete stub objects; exotic Docker-API-compatible daemons; very old or mismatched docker-py versions against the daemon.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/466ba8a3f13560a1. Report an issue: GitHub.