I'm looking for some guidance on how to effectively constrain CPU and memory resources using Docker Compose. I've tried setting the following values in my YAML file, but it feels more like a soft limit than a hard one:
- mem_limit: 512m
- mem_reservation: 128m
- memswap_limit: 1g
- cpus: "0.5"
- cpuset: "1"
Is there a more reliable way to enforce these constraints?
2 Answers
I can relate! I'm also using Docker Compose and struggled to set up resource limits for my containers. It seems like the deploy options under the resources section can be tricky. Instead, try this configuration:
```yaml
deploy:
resources:
limits:
cpus: "1"
memory: 128m
```
This worked for me, but I heard it’s mostly for Docker Swarm. If you're not using Swarm, it might not apply directly, so keep that in mind.
Have you solved this yet? I'm currently dealing with similar issues in Docker Compose and modifying the CPU and memory settings hasn't been successful for me either. I receive errors when rebuilding my container with the updated YAML. It's frustrating!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically