Milvus Docker 部署教程

1. 环境准备

确保您的系统已安装:

  • Docker
  • Docker Compose
  • Python (用于运行客户端代码)

2. 项目结构

创建项目目录并设置以下文件:

plaintext 复制代码
milvus-docker/
├── docker-compose.yml
├── main.py

3. 配置文件

docker-compose.yml

yaml:d:\node_test\milvus-docker\docker-compose.yml 复制代码
version: '3.5'

services:
  etcd:
    container_name: milvus-etcd
    image: quay.io/coreos/etcd:v3.5.5
    environment:
      - ETCD_AUTO_COMPACTION_MODE=revision
      - ETCD_AUTO_COMPACTION_RETENTION=1000
      - ETCD_QUOTA_BACKEND_BYTES=4294967296
    volumes:
      - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd
    command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd

  minio:
    container_name: milvus-minio
    image: minio/minio:RELEASE.2023-03-20T20-16-18Z
    environment:
      MINIO_ACCESS_KEY: minioadmin
      MINIO_SECRET_KEY: minioadmin
    volumes:
      - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data
    command: minio server /minio_data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  standalone:
    container_name: milvus-standalone
    image: milvusdb/milvus:v2.3.3
    command: ["milvus", "run", "standalone"]
    environment:
      ETCD_ENDPOINTS: etcd:2379
      MINIO_ADDRESS: minio:9000
    volumes:
      - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus
    ports:
      - "19530:19530"
      - "9091:9091"
    depends_on:
      - "etcd"
      - "minio"

4. 启动服务

在项目目录下运行:

bash 复制代码
docker-compose up -d

这将启动三个容器:

  • milvus-etcd: 元数据存储
  • milvus-minio: 对象存储
  • milvus-standalone: Milvus 服务器

5. Python 客户端示例

安装 Python 依赖:

bash 复制代码
pip install pymilvus

main.py 示例代码

python:d:\node_test\milvus-docker\main.py 复制代码
from pymilvus import MilvusClient

# Authentication not enabled
client = MilvusClient("http://localhost:19530")

client.create_collection(collection_name="test_collection", dimension=5)

client.insert(
    collection_name="test_collection",
    data=[
         {"id": 0, "vector": [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592], "color": "pink_8682"},
         {"id": 1, "vector": [0.19886812562848388, 0.06023560599112088, 0.6976963061752597, 0.2614474506242501, 0.838729485096104], "color": "red_7025"},
         {"id": 2, "vector": [0.43742130801983836, -0.5597502546264526, 0.6457887650909682, 0.7894058910881185, 0.20785793220625592], "color": "orange_6781"},
         {"id": 3, "vector": [0.3172005263489739, 0.9719044792798428, -0.36981146090600725, -0.4860894583077995, 0.95791889146345], "color": "pink_9298"},
         {"id": 4, "vector": [0.4452349528804562, -0.8757026943054742, 0.8220779437047674, 0.46406290649483184, 0.30337481143159106], "color": "red_4794"},
         {"id": 5, "vector": [0.985825131989184, -0.8144651566660419, 0.6299267002202009, 0.1206906911183383, -0.1446277761879955], "color": "yellow_4222"},
         {"id": 6, "vector": [0.8371977790571115, -0.015764369584852833, -0.31062937026679327, -0.562666951622192, -0.8984947637863987], "color": "red_9392"},
         {"id": 7, "vector": [-0.33445148015177995, -0.2567135004164067, 0.8987539745369246, 0.9402995886420709, 0.5378064918413052], "color": "grey_8510"},
         {"id": 8, "vector": [0.39524717779832685, 0.4000257286739164, -0.5890507376891594, -0.8650502298996872, -0.6140360785406336], "color": "white_9381"},
         {"id": 9, "vector": [0.5718280481994695, 0.24070317428066512, -0.3737913482606834, -0.06726932177492717, -0.6980531615588608], "color": "purple_4976"}
     ],
)



res = client.get(
    collection_name="test_collection",
    ids=1
)

print(res)
"""
(milvus-docker) D:\node_test\milvus-docker>uv run main.py
data: ["{'id': 1, 'vector': [np.float32(0.19886813), np.float32(0.060235605), np.float32(0.6976963), np.float32(0.26144746), np.float32(0.8387295)], 'color': 'red_7025'}"]
"""

6. 验证部署

运行 Python 示例代码:

bash 复制代码
python main.py

如果看到类似以下输出,说明部署成功:

复制代码
data: ["{'id': 1, 'vector': [np.float32(0.19886813), np.float32(0.060235605), np.float32(0.6976963), np.float32(0.26144746), np.float32(0.8387295)], 'color': 'red_7025'}"]

7. 服务管理

  • 停止服务:
bash 复制代码
docker-compose down
  • 查看日志:
bash 复制代码
docker-compose logs -f
  • 重启服务:
bash 复制代码
docker-compose restart

参考链接:https://milvus.io/api-reference/pymilvus/v2.4.x/MilvusClient/Vector/query.md

相关推荐
贝锐13 分钟前
Docker部署Teemii本地漫画库,并通过花生壳内网穿透实现远程访问
docker
观测云3 小时前
Kubernetes CRD 方式配置容器日志采集最佳实践
容器·kubernetes·日志分析
i***22074 小时前
springboot整合libreoffice(两种方式,使用本地和远程的libreoffice);docker中同时部署应用和libreoffice
spring boot·后端·docker
羑悻的小杀马特6 小时前
轻量跨云·掌控无界:Portainer CE + cpolar 让远程容器运维像点外卖一样简单——免复杂配置,安全直达对应集群
运维·网络·安全·docker·cpolar
EAIReport11 小时前
企业级报表自动化:基于Docker的部署实践
运维·docker·自动化
tianyuanwo13 小时前
多平台容器化RPM构建流水线全指南:Fedora、CentOS与Anolis OS
linux·运维·容器·centos·rpm
敲上瘾16 小时前
【探索实战】:Kurator分布式统一应用分发平台的全面解析与实践指南
分布式·容器·kubernetes·serverless
cui_win16 小时前
Docker Compose 部署一个完整的Prometheus监控告警系统
docker·容器·prometheus
ALex_zry20 小时前
Docker Compose运维技术实战分享:从安装到架构解析
运维·docker·架构
roman_日积跬步-终至千里1 天前
【Docker】Docker Stop 后到底发生了什么?——从信号机制到优雅停机
运维·docker·容器