All-Hands-AI / OpenHands

🙌 OpenHands: Code Less, Make More
https://all-hands.dev
MIT License
31.27k stars 3.61k forks source link

[Bug]: Error Fetching Docker API Version: FileNotFoundError on Startup #1564

Closed StackShipping closed 4 months ago

StackShipping commented 4 months ago

Is there an existing issue for the same bug?

Describe the bug

When attempting to start the opendevin container with Docker, I encountered a FileNotFoundError related to accessing the Docker API. This issue prevents the application from initiating correctly, resulting in the termination of the startup process.

Environment Operating System: Windows 11 Pro Docker Version: Latest WSL Version: Ubuntu WSL V.2 Opendevin Version: 0.3.1 Steps to Reproduce Open terminal (or command prompt/PowerShell). Execute the Docker run command:


sudo docker run -e SANDBOX_TYPE=exec -e GEMINI_API_KEY=<API_Key> -e LLM_MODEL=<Model> -e DOCKER_HOST=unix:///var/run/docker.sock -p 3000:3000 ghcr.io/opendevin/opendevin:0.3.1

Enter the sudo password when prompted. Observe the output, leading to a FileNotFoundError. Expected Behavior The Opendevin application should start without errors, and the Docker API should be accessed successfully.

Actual Behavior The application fails to start, outputting a FileNotFoundError regarding the Docker socket (/var/run/docker.sock). The complete traceback indicates issues in connecting to the Docker daemon, suggesting potential permissions or Docker service issues.

Current Version

ghcr.io/opendevin/opendevin:0.3.1

Installation and Configuration

sudo docker run -e SANDBOX_TYPE=exec -e GEMINI_API_KEY=<API_Key> -e LLM_MODEL=<Model> -e DOCKER_HOST=unix:///var/run/docker.sock -p 3000:3000 ghcr.io/opendevin/opendevin:0.3.1

Model and Agent

-Gemini 1.5 Pro

Reproduction Steps

No response

Logs, Errors, Screenshots, and Additional Context

INFO:     Started server process [1]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3000 (Press CTRL+C to quit)
INFO:     ('172.17.0.1', 53066) - "WebSocket /ws?token=<APPKEYTOKEN>" [accepted]
INFO:     connection open
Starting loop_recv for sid: 81cbf640-fb35-447b-89b4-de840b48fc8c
INFO:     172.17.0.1:53088 - "GET /api/messages/total HTTP/1.1" 200 OK
INFO:     172.17.0.1:53076 - "GET /api/configurations HTTP/1.1" 200 OK
17:05:53 - opendevin:ERROR: exec_box.py:55 - Please check Docker is running using `docker ps`.
17:05:53 - opendevin:ERROR: agent.py:127 - Error creating controller: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/app/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 400, in request
    self.endheaders()
  File "/usr/local/lib/python3.12/http/client.py", line 1331, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.12/http/client.py", line 1091, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.12/http/client.py", line 1035, in send
    self.connect()
  File "/app/.venv/lib/python3.12/site-packages/docker/transport/unixconn.py", line 27, in connect
    sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/app/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/app/.venv/lib/python3.12/site-packages/urllib3/connection.py", line 400, in request
    self.endheaders()
  File "/usr/local/lib/python3.12/http/client.py", line 1331, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.12/http/client.py", line 1091, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.12/http/client.py", line 1035, in send
    self.connect()
  File "/app/.venv/lib/python3.12/site-packages/docker/transport/unixconn.py", line 27, in connect
    sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/docker/api/client.py", line 213, in _retrieve_server_version
    return self.version(api_version=False)["ApiVersion"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/docker/api/daemon.py", line 181, in version
    return self._result(self._get(url), json=True)
                        ^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/docker/utils/decorators.py", line 44, in inner
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/docker/api/client.py", line 236, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/opendevin/server/agent/agent.py", line 118, in create_controller
    self.controller = AgentController(
                      ^^^^^^^^^^^^^^^^
  File "/app/opendevin/controller/agent_controller.py", line 51, in __init__
    self.command_manager = CommandManager(self.id, container_image)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/opendevin/controller/command_manager.py", line 20, in __init__
    self.shell = DockerExecBox(
                 ^^^^^^^^^^^^^^
  File "/app/opendevin/sandbox/exec_box.py", line 57, in __init__
    raise ex
  File "/app/opendevin/sandbox/exec_box.py", line 53, in __init__
    self.docker_client = docker.from_env()
                         ^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/docker/client.py", line 94, in from_env
    return cls(
           ^^^^
  File "/app/.venv/lib/python3.12/site-packages/docker/client.py", line 45, in __init__
    self.api = APIClient(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/docker/api/client.py", line 197, in __init__
    self._version = self._retrieve_server_version()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/docker/api/client.py", line 220, in _retrieve_server_version
    raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
rbren commented 4 months ago

@StackShipping you need to be able to run docker without sudo. See e.g. https://www.baeldung.com/linux/docker-run-without-sudo

rbren commented 4 months ago

See also: https://opendevin.github.io/OpenDevin/modules/usage/troubleshooting#unable-to-connect-to-docker