Docker memory usage limits
By default, Docker containers have no limit on server RAM usage, which can lead to memory insufficiency even with just one container.
The memory usage limit is set via the LimitNOFILE parameter, which is located in the service files:
- For Docker in general -
/usr/lib/systemd/system/docker.service - For each container individually -
/usr/lib/systemd/system/containerd.service
The value for this parameter is specified in the number of files. For example, to limit the number of files in each container to 4096, change the parameter in the /usr/lib/systemd/system/containerd.service file:
LimitNOFILE=4096Alternatively, instead of a hard limit, you can set a pair of soft and hard limits:
LimitNOFILE=4096:6148In this case, warnings will appear when the soft limit of 4096 files is reached, but the process can, if necessary, increase the number of files to 6148, which is the hard limit.
After making the changes, restart the services:
systemctl deamon-relaod и
systemctl stop containerd docker
systemctl start containerd docker