目录
报错起因
我启动了Milvus数据库
bash
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1099dda8c0fa milvusdb/milvus:v2.4.1 "/tini -- milvus run..." 17 minutes ago Up 17 minutes (healthy) 0.0.0.0:9091->9091/tcp, :::9091->9091/tcp, 0.0.0.0:19530->19530/tcp, :::19530->19530/tcp milvus-standalone
acafc6ef57bc quay.io/coreos/etcd:v3.5.5 "etcd -advertise-cli..." 17 minutes ago Up 17 minutes (healthy) 2379-2380/tcp milvus-etcd
587d1ee57611 minio/minio:latest "/usr/bin/docker-ent..." 17 minutes ago Up 17 minutes (healthy) 0.0.0.0:9000-9001->9000-9001/tcp, :::9000-9001->9000-9001/tcp milvus-minio
可以看到运行都很正常,但是我在另外一个容器中写代码访问19530端口,失败
另外这个容器在启动时(docker run)未设置--network host
报错内容
bash
Traceback (most recent call last):
File "/home/rag/startup.py", line 910, in <module>
client = MilvusClient(uri=Milvus_Client_URI,db_name=Milvus_DB_NAME)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/milvus_client/milvus_client.py", line 60, in __init__
self._using = self._create_connection(
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/milvus_client/milvus_client.py", line 728, in _create_connection
raise ex from ex
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/milvus_client/milvus_client.py", line 725, in _create_connection
connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/orm/connections.py", line 449, in connect
connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/orm/connections.py", line 400, in connect_milvus
gh._wait_for_channel_ready(timeout=timeout)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 150, in _wait_for_channel_ready
raise MilvusException(
pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on 172.17.0.2:19530, illegal connection params or server unavailable)>
这里的172.17.0.2来自于
bash
import socket
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.254.254.254', 1))
IP = s.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
s.close()
return IP
host = get_ip_address()
后面尝试更换为0.0.0.0
bash
Traceback (most recent call last):
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 147, in _wait_for_channel_ready
grpc.channel_ready_future(self._channel).result(timeout=timeout)
File "/root/miniconda3/lib/python3.10/site-packages/grpc/_utilities.py", line 162, in result
self._block(timeout)
File "/root/miniconda3/lib/python3.10/site-packages/grpc/_utilities.py", line 106, in _block
raise grpc.FutureTimeoutError()
grpc.FutureTimeoutError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/orm/connections.py", line 449, in connect
connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/orm/connections.py", line 400, in connect_milvus
gh._wait_for_channel_ready(timeout=timeout)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 150, in _wait_for_channel_ready
raise MilvusException(
pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on 0.0.0.0:19530, illegal connection params or server unavailable)>
更换为127.0.0.1
bash
Traceback (most recent call last):
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 147, in _wait_for_channel_ready
grpc.channel_ready_future(self._channel).result(timeout=timeout)
File "/root/miniconda3/lib/python3.10/site-packages/grpc/_utilities.py", line 162, in result
self._block(timeout)
File "/root/miniconda3/lib/python3.10/site-packages/grpc/_utilities.py", line 106, in _block
raise grpc.FutureTimeoutError()
grpc.FutureTimeoutError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/orm/connections.py", line 449, in connect
connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/orm/connections.py", line 400, in connect_milvus
gh._wait_for_channel_ready(timeout=timeout)
File "/root/miniconda3/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 150, in _wait_for_channel_ready
raise MilvusException(
pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on 127.0.0.1:19530, illegal connection params or server unavailable)>
以上都是无效的
解决方案
首先查看容器所在网段
bash
docker network ls
得到
bash
NETWORK ID NAME DRIVER SCOPE
738c89ed339b bridge bridge local
62ec1478cea1 host host local
5dc70a167a10 milvus bridge local
4d746c095f03 minio_default bridge local
40c6e5fbe685 mysql8_default bridge local
b101e25dcb4e nginx_default bridge local
接下来查看milvus的IP信息
bash
docker network inspect milvus
得到
bash
[
{
"Name": "milvus",
"Id": "5dc70a167a103d723fe81bc0feb95b996995d3d464f9601ce9c52d10342e3a6c",
"Created": "2024-10-12T13:55:27.648549485+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"40fd07ae3cdb975afedaf9861117aae38cddb0e63c977d14891d4af860c2885d": {
"Name": "eager_solomon",
"EndpointID": "a9b87ca7cb773953361e58b761b20f2d90f9a0c222dc2ce1fca08238dd0cb1cf",
"MacAddress": "02:42:ac:12:00:05",
"IPv4Address": "172.18.0.5/16",
"IPv6Address": ""
},
"6453a43e6cfa6b13b5a043bf62255447dbef1ce86876bdcdee55f6520f651bb5": {
"Name": "milvus-minio",
"EndpointID": "e977606fab9781521fa9dfcd8fcdec032b58daca9d7449cbc338c78ecbca1646",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
},
"957671f5a506146d5381e26f8afc22c5d2c5566678043a054d2cc4d0febd8873": {
"Name": "milvus-etcd",
"EndpointID": "4c0c44610d15254f53ea9839d34bdbf841427fcf6f7ef097b82c95694b5422c4",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"e6c952ee5bd431adf2c5bb3daf643612a4811f5155c46d46ac73607a845830ee": {
"Name": "milvus-standalone",
"EndpointID": "9fb76ce838126cf651d43360342b96ad1184b8ba37f4ab92e022ccb5fae38cf0",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "milvus",
"com.docker.compose.project": "milvus",
"com.docker.compose.version": "1.29.2"
}
}
]
看到milvus-standalone
的IPv4地址为172.18.0.4
最终用这个地址链接成功