多数的应⽤场景要对Docker容器的运⾏内存进⾏限制,防⽌其使⽤过多的内存。
格式:-m或--memory
正常的内存大小
[root@admin ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bd9b6b85169d registry:latest "/entrypoint.sh /etc…" 2 days ago Up 5 minutes 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp registry
[root@admin ~]#
[root@admin ~]# docker inspect registry | grep "Memory""Memory": 0,"MemoryReservation": 0,"MemorySwap": 0,"MemorySwappiness": null,
指定内存大小
[root@admin ~]# docker run -id --name abcd -m 128M registry
49939194977c03d58e38be1fcb0cbefd8df1d614331b34e70c741bb0e47a3cc2
[root@admin ~]# docker inspect abcd | grep "Memory""Memory": 134217728,"MemoryReservation": 0,"MemorySwap": 268435456,"MemorySwappiness": null,
[root@admin ~]#
⼤多数的应⽤场景要对Docker容器的CPU利⽤率进⾏限制,防⽌其使⽤过多的CPU。 在Docker容器运⾏时,我们可以使⽤参数–cpuset来绑定CPU,使得该Docker容器只在固 定的CPU上运⾏。
格式:--cpuset-cpus
原始cpu
[root@admin ~]# docker inspect registry | grep "CpusetCpus""CpusetCpus": "",
[root@admin ~]#
[root@admin ~]# docker run -id --name xcpu --cpuset-cpus 1 registry
3b1eca3ed5d561014241887208cee3c507aac658cefcd41f23f44ab08c6c9286
[root@admin ~]# docker inspect xcpu | grep Cpu"CpuShares": 0,"NanoCpus": 0,"CpuPeriod": 0,"CpuQuota": 0,"CpuRealtimePeriod": 0,"CpuRealtimeRuntime": 0,"CpusetCpus": "1", //核心数"CpusetMems": "","CpuCount": 0,"CpuPercent": 0,