Memory Limit in Docker
When we create a new container, it has unlimited access to system resources, so if one occupies all the memory, the other containers will be affected or, failing that, the operating system runs out of resources.
Docker has the ability to apply a memory limit to a specific container.
Creating a Container
1$ docker run --name dell -it debian bash
Obtaining Container Information
1$ docker inspect dell | grep -i 'Memory'
For "Memory": 0 the value 0 indicates that the container doesn't have a limited memory value, that is, it will use everything that the host has available, possibly affecting other containers that are within the same host.
Update Container Memory
1$ docker update -m 256MB dell
In testing there were problems on Debian and Ubuntu operating systems:
This problem is due to the fact that the cgroup is not mounted on the system, to mount it we edit the file grub.
1$ sudo vim /etc/default/grub 2 ... 3 GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1" 4 GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1" 5 ...
Update grub and restart system:
1$ sudo update-grub 2$ sudo update-grub2 3$ sudo reboot
Finally we run the command to update the memory again and check the memory status: