Skip to content

Commit f0709f0

Browse files
committed
docs: clarify byte units for size-based ulimits (memlock)
The values for size-based ulimits, such as memlock, data, and fsize, are passed to the setrlimit(2) syscall as-is, and are therefore expressed in bytes. This differs from the ulimit shell builtin, which reports several of these limits in kilobytes, which has proven to be a source of confusion (--ulimit memlock=4096 results in a 4 KiB limit, reported by "ulimit -l" as "4"). Document the units explicitly, mention that values must be plain integers without unit suffixes, and add a memlock example showing the byte value alongside the corresponding "ulimit -l" output. Signed-off-by: Dean Chen <862469039@qq.com>
1 parent 7a54334 commit f0709f0

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

docs/reference/commandline/container_run.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,21 @@ $ docker run --ulimit nofile=1024:1024 --rm debian sh -c "ulimit -n"
13701370
| `stack` | Maximum stack size (`RLIMIT_STACK`) |
13711371
13721372
Docker sends the values to the appropriate OS `syscall` and doesn't perform any byte conversion.
1373-
Take this into account when setting the values.
1373+
For limits that describe a size, such as `memlock`, `data`, and `fsize`, values
1374+
are in bytes, following the semantics of the Linux `setrlimit(2)` syscall.
1375+
Values must be plain integers, and don't support unit suffixes such as `k`,
1376+
`m`, or `g`.
1377+
1378+
> [!NOTE]
1379+
> The `ulimit` shell builtin reports some of these limits in different units.
1380+
> For example, `ulimit -l` reports the `memlock` limit in kilobytes, so a limit
1381+
> of 64 MiB set with `--ulimit memlock=67108864:67108864` is reported as
1382+
> `65536`:
1383+
>
1384+
> ```console
1385+
> $ docker run --ulimit memlock=67108864:67108864 --rm debian sh -c "ulimit -l"
1386+
> 65536
1387+
> ```
13741388
13751389
#### For `nproc` usage
13761390

man/docker-run.1.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,15 @@ any options, the systems uses the following options:
740740
Without this argument the command will be run as root in the container.
741741

742742
**--ulimit**=[]
743-
Ulimit options
743+
Ulimit options, in the format `<type>=<soft limit>[:<hard limit>]`, for
744+
example `--ulimit nofile=1024:1024`.
745+
746+
Limits that describe a size, such as `memlock`, `data`, and `fsize`, are
747+
specified in bytes, as used by the Linux setrlimit(2) syscall. Values must
748+
be plain integers, and don't support unit suffixes such as `k`, `m`, or
749+
`g`. Note that the `ulimit` builtin of the shell reports some of these
750+
limits in different units, for example, `ulimit -l` reports the `memlock`
751+
limit in kilobytes.
744752

745753
**-v**|**--volume**[=*[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*]
746754
Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR`, Docker

0 commit comments

Comments
 (0)