Back to Container

Resource limits (ulimits)

docs/ulimits.md

1.3.02.7 KB
Original Source

Resource limits (ulimits)

Set per-process resource limits for your containers.

Overview

The --ulimit option of container run (and container create) sets Linux resource limits (rlimits) for the container's init process.

Syntax

bash
container run --ulimit <type>=<soft>[:<hard>] ...

If you set a single value, it applies as both soft and hard limit:

bash
container run --ulimit nofile=65536 -it ubuntu:24.04 bash

Set soft and hard limits independently:

bash
container run --ulimit nofile=65536:131072 -it ubuntu:24.04 bash

Set multiple limits by repeating the flag:

bash
container run --ulimit nofile=65536:131072 --ulimit cpu=60 -it ubuntu:24.04 bash

Use unlimited for no limit:

bash
container run --ulimit nproc=unlimited -it ubuntu:24.04 bash

[!NOTE] nofile=unlimited reliably fails to start the container (NSPOSIXErrorDomain Code=1 "Operation not permitted"). This isn't a container bug — unlimited sets both soft and hard limits to UINT64_MAX, and Linux caps RLIMIT_NOFILE's hard limit at the guest's /proc/sys/fs/nr_open (1048576 here); anything above that ceiling fails the same way, unlimited included. Use an explicit value at or below nr_open instead, e.g. nofile=1048576.

Supported limit types

TypeMaps toDescription
coreRLIMIT_COREMaximum core file size, in bytes
cpuRLIMIT_CPUMaximum CPU time, in seconds
dataRLIMIT_DATAMaximum data segment size, in bytes
fsizeRLIMIT_FSIZEMaximum file size, in bytes
locksRLIMIT_LOCKSMaximum number of file locks
memlockRLIMIT_MEMLOCKMaximum amount of memory that may be locked into RAM
msgqueueRLIMIT_MSGQUEUEMaximum bytes in POSIX message queues
niceRLIMIT_NICEMaximum nice priority
nofileRLIMIT_NOFILEMaximum number of open file descriptors
nprocRLIMIT_NPROCMaximum number of processes
rssRLIMIT_RSSMaximum resident set size, in bytes
rtprioRLIMIT_RTPRIOMaximum real-time priority
rttimeRLIMIT_RTTIMEMaximum real-time CPU time, in microseconds
sigpendingRLIMIT_SIGPENDINGMaximum number of pending signals
stackRLIMIT_STACKMaximum stack size, in bytes

Inspect limits inside a container

console
% container run -it --rm ubuntu:24.04 bash -c "ulimit -a"
open files                          (-n) 1048576
cpu time                   (seconds, -t) unlimited
...
% container run --ulimit nofile=131072 --ulimit cpu=60 -it --rm ubuntu:24.04 bash -c "ulimit -a"
open files                          (-n) 131072
cpu time                   (seconds, -t) 60
...