docker可以通過啟動命令來限制容器可以使用的最大物理內存和swap,但是通常在使用這些命令的時候經常會碰到“WARNING: No swap limit support”警告
大概意思就是不支持swap內存的限制,所以在使用,在國內的騰訊雲和阿里雲服務器上測試都是報這個警告的。
限制docker容器最大內存使用量
參數:-m 64M --memory-swap=128M
-m 64M 限制了容器運行可以使用的最大物理內存為64M,--memory-swap=128M限制容器可以使用的最大虛擬內存為128M,在出現WARNING: No swap limit support警告時這兩個參數是無效的。
解決方法:
1、編輯/etc/default/grub文件。
在GRUB_CMDLINE_LINUX=" ",中並追加 cgroup_enable=memory swapaccount=1
yang@master:~$ cat /etc/default/grub # If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="maybe-ubiquity" GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
注:如果GRUB_CMDLINE_LINUX=內有內容,切記不可刪除,只需在后面追加cgroup_enable=memory swapaccount=1並用空格和前面的內容分隔開。
2、保存,更新
yang@master:~$ sudo update-grub
3、重啟服務器
yang@master:~$ sudo reboot
4、查看
yang@master:~$ docker info Client: Context: default Debug Mode: false Plugins: ..... Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
