docker运行“–memory”选项的单位是什么?
我想限制一个Docker容器的内存为1 GB。 根据文档,我们可以使用--memory
选项指定所需的内存限制:
$ docker run --memory <size> ...
但是, 文档 没有描述页面上任何位置的参数的格式或单位 :
– 内存,-m内存限制
我应该提供哪些单元 – --memory
和其他相关选项,如--memory-reservation
和--memory-swap
? 只是字节?
从docker文档中取得 :
限制容器对内存的访问Docker可以实施硬性内存限制,允许容器使用不超过给定数量的用户或系统内存,或软限制,允许容器使用尽可能多的内存,除非有特定的条件例如当内核检测到主机上的内存不足或争用时。 其中一些选项在单独使用或设置了多个选项时会有不同的效果。
这些选项大部分都采用正整数,后跟
b
,k
,m
,g
后缀来表示字节,千字节,兆字节或千兆字节。
在Windows上运行Docker时, 此页面还包含有关内存限制的一些额外信息。
我的经典案例RTFM。 --memory
选项支持单元后缀,所以我们不需要计算确切的字节数:
-m, --memory="" Memory limit (format: <number>[<unit>], where unit = b, k, m or g) Allows you to constrain the memory available to a container. If the host supports swap memory, then the -m memory setting can be larger than physical RAM. If a limit of 0 is specified (not using -m), the container's memory is not limited. The actual limit may be rounded up to a multiple of the operating system's page size (the value would be very large, that's millions of trillions).
因此,要启动容量为1 GB的容器(如问题中所述),这两个命令都可以工作:
$ docker run --memory 1g ... $ docker run --memory 1073741824 ...
--memory-reservation
和--memory-swap
选项也支持这个约定。