Repository: Giskard-AI/giskard-oss
Issue: Giskard Hub fails to start in MacOS with colima
Root cause: Environment Incompatibility

### Issue Type

Bug

### Source

source

### Giskard Library Version

2.7.6

### Giskard Hub Version

nil

### OS Platform and Distribution

Mac OS 14.4

### Python version

3.9.6

### Installed python packages

_No response_

### Current Behaviour?

```shell
Giskard hub is not starting for me.

I am using [colima](https://github.com/abiosoft/colima) to manage my docker.

When running `giskard hub start`, 
it gives error saying:
`Message: 'Failed to connect to Docker. Giskard requires Docker to be installed. If Docker is installed, please run it. Otherwise, please install it.\nFor an easy installation of Docker you can execute:\n- sudo curl -fsSL https://get.docker.com -o get-docker.sh\n- sudo sh get-docker.sh'
Arguments: (DockerException("Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))"),)`


However, colima has been running in the background and I am able to run other docker containers quite fine separately.



I later tested out the same command on a linux machine without colima and at that time giskard hub started fine.
It seems like giskard hub has some issues when connecting to docker instances which are managed by colima
```


### Standalone code OR list down the steps to reproduce the issue

```shell
- Manage docker using colima
- Start colima
- Create new pythong project and install giskard[hub]
- Try to start giskard hub
- Gets error message saying: 'Failed to connect to Docker. Giskard requires Docker to be installed. If Docker is installed, please run it. Otherwise, please install it'
```


### Relevant log output

```shell
/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
  warnings.warn(
2024-03-15 12:19:51,810 pid:45842 MainThread giskard.commands.cli_hub INFO     Starting Giskard Hub
--- Logging error ---
Traceback (most recent call last):
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/connection.py", line 400, in request
    self.endheaders()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/http/client.py", line 1252, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/http/client.py", line 1012, in _send_output
    self.send(msg)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/http/client.py", line 952, in send
    self.connect()
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/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 "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/urllib3/connection.py", line 400, in request
    self.endheaders()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/http/client.py", line 1252, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/http/client.py", line 1012, in _send_output
    self.send(msg)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/http/client.py", line 952, in send
    self.connect()
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/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 "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/docker/api/client.py", line 213, in _retrieve_server_version
    return self.version(api_version=False)["ApiVersion"]
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/docker/api/daemon.py", line 181, in version
    return self._result(self._get(url), json=True)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/docker/utils/decorators.py", line 44, in inner
    return f(self, *args, **kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/docker/api/client.py", line 236, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/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 "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/giskard/commands/cli_hub.py", line 32, in create_docker_client
    return docker.from_env()
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/docker/client.py", line 94, in from_env
    return cls(
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/docker/client.py", line 45, in __init__
    self.api = APIClient(*args, **kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/docker/api/client.py", line 197, in __init__
    self._version = self._retrieve_server_version()
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/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'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1083, in emit
    msg = self.format(record)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 927, in format
    return fmt.format(record)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 663, in format
    record.message = record.getMessage()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 367, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/bin/giskard", line 8, in <module>
    sys.exit(cli())
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/giskard/cli_utils.py", line 34, in wrapper
    return func(*args, **kwargs)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/giskard/commands/cli_hub.py", line 342, in start
    _start(attached, skip_version_check, version, environment)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/giskard/commands/cli_hub.py", line 145, in _start
    _pull_image(version)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/giskard/commands/cli_hub.py", line 193, in _pull_image
    if not _check_downloaded(version):
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/giskard/commands/cli_hub.py", line 183, in _check_downloaded
    create_docker_client().images.get(image)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/giskard/commands/cli_hub.py", line 34, in create_docker_client
    logger.exception(
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1481, in exception
    self.error(msg, *args, exc_info=exc_info, **kwargs)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1475, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1589, in _log
    self.handle(record)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1599, in handle
    self.callHandlers(record)
  File "/Users/aldrinjenson/Projects/x-hallucitor/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/logging.py", line 100, in sentry_patched_callhandlers
    return old_callhandlers(self, record)
Message: 'Failed to connect to Docker. Giskard requires Docker to be installed. If Docker is installed, please run it. Otherwise, please install it.\nFor an easy installation of Docker you can execute:\n- sudo curl -fsSL https://get.docker.com -o get-docker.sh\n- sudo sh get-docker.sh'
Arguments: (DockerException("Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))"),)
```


Hi @aldrinjenson ,

Giskard CLI uses Docker python SDK to run the hub in a container. It looks like the Docker SDK isn't compatible with Colima.

You can try starting Giskard Hub manually by running
```
docker run -p 7860:7860  giskardai/giskard:latest
```

and then opening Giskard on port 7860

According to colima doc, could you plz run `colima status` and check whether there is something like:

```
INFO[0000] socket: unix:///Users/xxxxxx/.colima/default/docker.sock
```

By default, Docker Python lib uses `base_url='unix://var/run/docker.sock'` to communicate with a Docker compatible daemon.

You can check and set the `DOCKER_HOST` env for Giskard to the `unix://Users/xxxxxx/.colima/default/docker.sock` on your Mac.

Hi @Inokinoki and @andreybavt ,


Thank You for the quick response. 

Indeed when running `colima status` I was having a line similar to 
`INFO[0000] socket: unix:///Users/<username>/.colima/default/docker.sock`

Once i exported this to `DOCKER_HOST` then everything is working as expected.

Thanks again. The issue is resolved.