docker-composemilvus

Unable to Connect to Milvus Database Using PyMilvus with Standalone Deployment via Docker Compose


I'm trying to run Milvus in standalone mode using Docker Compose, but I am unable to connect to the database using PyMilvus.

Here’s the setup I am using:

I first running as https://milvus.io/docs/install_standalone-docker-compose.md say:

wget https://github.com/milvus-io/milvus/releases/download/v2.5.0-beta/milvus-standalone-docker-compose.yml -O docker-compose.yml

sudo docker compose up -d

Then I create a simple python code like:

from pymilvus import connections

# Use host and port
connections.connect(
  alias="default", 
  host='localhost', 
  port='19530'
)

After running it, I got connection error:

(/home_backup/xiaowentao/miniconda/conda_base_env_pkg/conda-envs/base_env_3_11) xiaowentao@host-04:/docker-home/xiaowentao/CAVDTUNER/milvus-standalone-test/source$ python test_connection.py 
Traceback (most recent call last):
  File "/home_backup/xiaowentao/miniconda/conda_base_env_pkg/conda-envs/base_env_3_11/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py", line 131, in _wait_for_channel_ready
    grpc.channel_ready_future(self._channel).result(timeout=timeout)
  File "/home_backup/xiaowentao/miniconda/conda_base_env_pkg/conda-envs/base_env_3_11/lib/python3.11/site-packages/grpc/_utilities.py", line 151, in result
    self._block(timeout)
  File "/home_backup/xiaowentao/miniconda/conda_base_env_pkg/conda-envs/base_env_3_11/lib/python3.11/site-packages/grpc/_utilities.py", line 97, in _block
    raise grpc.FutureTimeoutError()
grpc.FutureTimeoutError

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

Traceback (most recent call last):
  File "/docker-home/xiaowentao/CAVDTUNER/milvus-standalone-test/source/test_connection.py", line 4, in <module>
    connections.connect(
  File "/home_backup/xiaowentao/miniconda/conda_base_env_pkg/conda-envs/base_env_3_11/lib/python3.11/site-packages/pymilvus/orm/connections.py", line 355, in connect
    connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
  File "/home_backup/xiaowentao/miniconda/conda_base_env_pkg/conda-envs/base_env_3_11/lib/python3.11/site-packages/pymilvus/orm/connections.py", line 302, in connect_milvus
    gh._wait_for_channel_ready(timeout=timeout)
  File "/home_backup/xiaowentao/miniconda/conda_base_env_pkg/conda-envs/base_env_3_11/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py", line 134, in _wait_for_channel_ready
    raise MilvusException(
pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on localhost:19530. Timeout)>

I try this command line and verify that three docker containers are running normally:

docker ps | grep "milvus"
215ca6b1b9c1   milvusdb/milvus:v2.5.0-beta                      "/tini -- milvus run…"   About a minute ago   Up About a minute (healthy)   0.0.0.0:9091->9091/tcp, :::9091->9091/tcp, 0.0.0.0:19530->19530/tcp, :::19530->19530/tcp   milvus-standalone
6d5fc50c9b77   minio/minio:RELEASE.2023-03-20T20-16-18Z         "/usr/bin/docker-ent…"   About a minute ago   Up About a minute (healthy)   0.0.0.0:9000-9001->9000-9001/tcp, :::9000-9001->9000-9001/tcp                              milvus-minio
357e614e1687   quay.io/coreos/etcd:v3.5.5                       "etcd -advertise-cli…"   About a minute ago   Up About a minute (healthy)   2379-2380/tcp                                                                              milvus-etcd


nc -zv 127.0.0.1 19530
Connection to 127.0.0.1 19530 port [tcp/*] succeeded!

How can I connect to Milvus using PyMilvus successfully? Is there any additional configuration I need to set?

Any help or guidance would be greatly appreciated!


Solution

  • I try to figure it out by this way:

    After setting up a proxy in the ~/.bashrc file with the following lines:

    export http_proxy="http://xxx:port"  
    export https_proxy="http://xxx:port"  
    

    attempting to connect to Milvus via 127.0.0.1 or localhost results in one of the following two errors (based on tests across different machines):

    Invalid connection parameters:

    pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on localhost:19530, illegal connection params or server unavailable)>
    

    Connection timeout:

    pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on localhost:19530. Timeout)>
    

    Root Cause: The proxy settings interfere with the networking between Docker containers, causing the connection to fail.

    Solution: To resolve this issue, temporarily disable the proxy settings by clearing the environment variables:

    export http_proxy=""  
    export https_proxy=""  
    source ~/.bashrc
    

    Once the proxy is disabled, reconnecting to Milvus will work as expected.

    If you encounter connection issues with Milvus while using proxies, ensure that the proxy settings do not affect local networking. This simple adjustment resolves the problem effectively.