docker 运行“--memory”选项需要什么单位?

Cy *_*nol 8 docker

我想将 Docker 容器的内存限制为 1 GB。根据文档,我们可以使用以下--memory选项指定所需的内存限制:

$ docker run --memory <size> ...
Run Code Online (Sandbox Code Playgroud)

但是,文档 没有描述页面上任何地方参数的格式或单位

--memory , -m 内存限制

我应该提供哪些单位--memory以及其他相关选项,例如--memory-reservation--memory-swap?只是字节?

Cy *_*nol 9

就我而言,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).
Run Code Online (Sandbox Code Playgroud)

因此,要按照问题中的描述启动具有 1 GB 内存限制的容器,这两个命令都将起作用:

$ docker run --memory 1g ... 
$ docker run --memory 1073741824 ...
Run Code Online (Sandbox Code Playgroud)

--memory-reservation--memory-swap选项也支持这一公约。