Search code examples
pythondockermilvus

Connect to Milvus standalone server (in docker container) from another docker container on the same host


When I run Milvus in standalone mode on docker (by executing docker-compose on the default Milvus docker-compose.yml file, resulting in the three containers being created), I cannot connect to the Milvus server from a task running in another docker container on the same host. I have configured this container to be on the same network as the Milvus server, and I can ping the Milvus server from this container via the Milvus server's IP.

In the task container I run:

connections.connect(
    alias="default", 
    host='192.168.192.4', 
    port='19530',
    secure=False
    )

The error log shows:

Traceback (most recent call last):
File "task.py", line 45, in
secure=True
File "/usr/local/lib/python3.7/site-packages/pymilvus/orm/connections.py", line 262, in connect
connect_milvus(**kwargs, password=password)
File "/usr/local/lib/python3.7/site-packages/pymilvus/orm/connections.py", line 233, in connect_milvus
gh._wait_for_channel_ready()
File "/usr/local/lib/python3.7/site-packages/pymilvus/client/grpc_handler.py", line 118, in _wait_for_channel_ready
raise MilvusException(Status.CONNECT_FAILED, f'Fail connecting to server on {self._address}. Timeout')
pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on 192.168.192.4:19530. Timeout)>

192.168.192.4 is the ip address of the milvus-standalone container.


Solution

  • Turns out this is not a Milvus issue. The problem was caused by our corporate network, and the proxy requirement. In the dockerfile, I need to set the proxy settings to be able to pull images. However, this sets the proxy settings during builld and for the container. These proxy settings prevented communication between the containers. The proxy setting needs to be reset in the dockerfile. The fix looked like this:

    FROM python:3.9.12
    
    ENV https_proxy <proxy settings>
    
    COPY requirements.txt /
    
    RUN pip3 install --proxy <proxy settings> -r requirements.txt
    
    COPY task.py /
    
    ENV https_proxy ""
    
    CMD ["python3", "-u", "task.py"]