Docker container memory limit method
- 2020-06-03 08:50:24
- OfStack
1. When using the -ES2en operation that comes with Docker for memory limitations, the following prompts may occur due to kernel limitations
Your kernel does not support swap limit capabilities.memory limit without swap
You must add by modifying the grub file /etc/default/grub:
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
Updating grub and restarting it can be done later
$ sudo update-grub
$ sudo reboot
2. Using es21EN-ES22en restricts memory to twice the input size
$ sudo docker run -it --name test -m 100m ubuntu /bin/bash
At this point the memory is limited to 200m
If you want to limit it to 100m, it must be executed
$ sudo docker run -it --name test -m 100m --memory-swap=100m ubuntu /bin/bash
Both memory and swap are limited to 100m
3. Memory pressure measurement tool stress
$ sudo apt-get install stress
$ sudo stress --vm 1 --vm-bytes 100M --vm-hang 0
If reality is killed within a few seconds after running, memory is limited to 100M