Limiting container memory

Hello All,

I have a container running in network mode as Host with the additional capability of SYS_NICE. I’m using Docker Compose to manage it.

I want to limit the container’s memory and have tried the following two methods:

  1. In docker compose (part of the docker compose is given here)

    mem_limit: 100m
    mem_reservation:50m

  2. In docker compose (part of the docker compose is given here)

deploy:
resources:
limits:
memory: 100M
reservations:
memory: 50M

In both the cases memory is not limited

“Memory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: -1,
“MemorySwappiness”: null,

What can be done to limit the memory?


Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
services:
  service1:
    image: image1
```

After fixing your post, please send a new comment so people are notified about the fixed content.


In case yu are using Rootless Docker, this documentation could be important:

https://docs.docker.com/engine/security/rootless/?uuid=c8fb7a34-5cf9-4f1b-8d4a-97bab770ce7c%0A#limiting-resources

Limiting resources

Limiting resources with cgroup-related docker run flags such as --cpus, --memory, --pids-limit is supported only when running with cgroup v2 and systemd. See Changing cgroup version to enable cgroup v2.