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
選項也支持這一公約。