How can I limit CPU and memory usage in Docker Compose?

0
7
Asked By TechieNinja92 On

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

Answered By DockerDude88 On

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.

Answered By ContainerQueen42 On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.