You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker Compose配置内存交换参数报错求助

Fixing Docker Compose Memory-Swap Configuration Error

Hey there! The error you're seeing comes from two key misconfigurations in your Compose file:

  1. Incorrect placement of memory-swap: In Docker Compose version 3, the memory-swap parameter doesn't belong under the reservations block — it's meant to be part of the limits section.
  2. reservations doesn't support memory-swap: The reservations block only accepts parameters like memory and cpus; memory-swap isn't a valid property here.

Corrected docker-compose.yml

version: '3'
services:
  moonlight:
    build: ./
    restart: unless-stopped
    hostname: moonlight
    deploy:
      resources:
        limits:
          memory: 4000M
          memory-swap: 12000M  # 4GB physical memory + 8GB swap = 12GB total
        reservations:
          memory: 2000M  # Optional: minimum memory reserved for the container
    ports:
      - "80:3001"

Key Notes to Keep in Mind:

  • Understanding memory-swap: This value represents the total amount of memory (physical + swap) the container can use. If you want the container to use all available swap space on your host, you can set memory-swap: -1 instead of a specific number.
  • Docker Daemon Swap Check: Ensure your Docker daemon allows swap usage. Check /etc/docker/daemon.json — if it exists, confirm it has "swaplimit": true. If not, add that line, save the file, and restart Docker with sudo systemctl restart docker.
  • Reservation is Optional: The reservations.memory sets a minimum memory guarantee for the container, but it's not required if you only need to set upper limits.

This should fix the invalid Compose file error and let your container utilize the swap space you created.

内容的提问来源于stack exchange,提问作者Dibeesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 14:23:14