Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

pymilvus times out connecting to Milvus on localhost:19530 from a container

ErrorMilvusException: (code=2, message=Fail connecting to server on localhost:19530. Timeout)

Short answer

Inside a container, localhost is the container itself, not the machine or the Milvus container, so the app gets a timeout on port 19530. Put the app and Milvus on the same Docker network, connect with the Milvus container or service name, and wait until Milvus reports healthy before connecting.

  • Applies to Milvus 2.x standalone, pymilvus 2.x, Docker Compose v2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check that Milvus is up and healthy, and see which networks it and your app are attached to.

    docker ps
    docker inspect --format '{{.State.Health.Status}}' milvus-standalone
  2. 2Match what you see, then jump to its fix

    1. 1The same code works on your host machine but times out once the app runs in a container.The app connects to localhost from inside its own containerFix
    2. 2The first connection after docker compose up times out, and a retry a minute later works.Milvus has not finished startingFix

What does the error look like?

  • MilvusException: (code=2, message=Fail connecting to server on localhost:19530. Timeout)

Cause 1 of 2

The app connects to localhost from inside its own container

1Check

A container has its own loopback address, so localhost inside the app container does not reach the Milvus container.

grep -rn "localhost:19530" .

2Fix

Use the service or container name on the shared network. Compose registers each service in Docker's internal DNS, and container-to-container traffic uses the container port.

from pymilvus import MilvusClient
client = MilvusClient(uri="http://milvus-standalone:19530")

3Verify

The client connects and calls succeed.

python -c "from pymilvus import MilvusClient; print(MilvusClient(uri='http://milvus-standalone:19530').list_collections())"

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 2

Milvus has not finished starting

1Check

The Milvus docs say to wait until the health status reads healthy before you continue.

docker inspect --format '{{.State.Health.Status}}' milvus-standalone

2Fix

Wait for healthy before starting the app, or retry the connection in your code.

until [ "$(docker inspect --format '{{.State.Health.Status}}' milvus-standalone)" = healthy ]; do sleep 5; done

3Verify

The status reads healthy and the client connects.

docker inspect --format '{{.State.Health.Status}}' milvus-standalone

Confirmed by milvus.io

Did this fix it?

How do I stop it coming back?

  • Put the Milvus address in an environment variable so one image works on a laptop and in Compose.
  • Run Milvus and the app in one Compose project so they share a network and can use each other's names.
  • Retry the first connection a few times instead of failing on the first timeout.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

AI

Ollama is slow and the GPU is not being used

Replies arrive a few tokens per second on a machine with a GPU

Run ollama ps and read the PROCESSOR column: 100% GPU means the model is on the card, anything with CPU means it is not fully there.

4 causes, each with a fix

AI

Open WebUI web search with SearXNG fails with 403

Web search returns no results with SearXNG selected

Open WebUI asks SearXNG for JSON results, and SearXNG refuses that unless json is listed in the formats in settings.yml.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.