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:
- Incorrect placement of
memory-swap: In Docker Compose version 3, thememory-swapparameter doesn't belong under thereservationsblock — it's meant to be part of thelimitssection. reservationsdoesn't supportmemory-swap: Thereservationsblock only accepts parameters likememoryandcpus;memory-swapisn'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 setmemory-swap: -1instead 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 withsudo systemctl restart docker. - Reservation is Optional: The
reservations.memorysets 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
相关产品推荐
相关产品推荐

