docker compose限制资源使用(cpu memory)

 

[root@localhost langfuse]# more docker-compose.yml 
services:
  langfuse-server:
    image: langfuse/langfuse:2
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
      - NEXTAUTH_SECRET=mysecret
      - SALT=mysalt
      - ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000 # generate via `openssl rand -hex 32`
      - NEXTAUTH_URL=http://localhost:3000
      - TELEMETRY_ENABLED=${TELEMETRY_ENABLED:-true}
      - LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES=${LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES:-false}
      - LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES=true
    deploy:
      resources:
        limits:
          memory: 512m  # 限制为使用512MB内存
          cpus: '0.5'  # 限制为使用半个CPU核心

  db:
    image: postgres:16.4
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 3s
      timeout: 3s
      retries: 10
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
    ports:
      - 5432:5432
    volumes:
      - /home/middle/langfuse/pgdata:/var/lib/postgresql/data
volumes:
  database_data:
    driver: local

 

posted @ 2025-09-15 16:51  slnngk  阅读(45)  评论(0)    收藏  举报