docker Run the operation of the specified memory
- 2021-10-27 09:45:16
- OfStack
As follows:
-m,--memory Memory limit, the format is numbers plus units, and the units can be b,k,m,g . Minimum is 4M
--memory-swap Memory + Total swap partition size limit. The format is the same as above. Must must -m Setting large
--memory-reservation Soft limits on memory. Same format as above
--oom-kill-disable Whether to block OOM killer Kill container, not set by default
--oom-score-adj Container is OOM killer The priority of killing, the range is [-1000, 1000] The default is 0
--memory-swappiness Used to set the virtual memory control behavior of the container. Value is 0~100 Integer between
--kernel-memory Core memory limit. The format is the same as above, and the minimum is 4M
View examples:
[root@sannian ~]# docker run -d -m 1G --memory-swap 3G -p 9999:80 --restart=always --name gitlab twang2218/gitlab-ce-zh
a3254078a79a084f3f3bed5f4ade3e26c7d86951cd822d95b113227d75b00097
[root@sannian ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3254078a79a twang2218/gitlab-ce-zh "/assets/wrapper" 21 minutes ago Up 2 minutes (healthy) 22/tcp, 443/tcp, 0.0.0.0:9999->80/tcp gitlab
[root@sannian ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
twang2218/gitlab-ce-zh latest 18da462b5ff5 3 months ago 1.61GB
registry-vpc.cn-hangzhou.aliyuncs.com/wenty/jumpserver latest 055f42f305f5 7 months ago 1.41GB
registry.cn-hangzhou.aliyuncs.com/wenty/jumpserver latest 055f42f305f5 7 months ago 1.41GB
registry.jumpserver.org/public/jumpserver 1.0.0 055f42f305f5 7 months ago 1.41GB
registry.jumpserver.org/public/jumpserver latest 055f42f305f5 7 months ago 1.41GB
Added: docker run-m Specified memory size does not work
When executing docker run, you want to specify the memory size under 1, and use the-m parameter
The error is reported as follows
#docker run -id -m 3g -p 7001:7001 197.3.16.51/sysmgr/mywebapptest_app_weblogic:20180820047 WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap. 52380a4896f3f916cd0f95f97e233b30d9406840e10c0c53484b3be9000d0321
Then I found that even though I set the heap size to 5G, the container was created and the 3g limit was not in effect.
Looking up the data, we found that this error was reported because the related functions of the host kernel were not turned on.
Solutions
Just follow the following settings
step 1:
Edit the document /etc/default/grub and change line GRUB_CMDLINE_LINUX1 to read
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
step 2:
Update GRUB, that is, execute $sudo update-grub
step 3:
Restart the system.