How to Manage Container Resources: CPU, Memory, and Linux Capabilities in Apple container
Purpose
This post demonstrates how to control CPU, memory, Linux capabilities, and other resource settings for Apple containers β both per-container and at the system level.
Per-Container CPU and Memory
Override defaults when running a container:

container run --cpus 4 --memory 4g my-imageDefault container resources are 4 CPUs and 1 GB RAM. Memory accepts K, M, G, T, P suffixes with 1 MiByte granularity (binary, not decimal).
Builder Resources
The builder VM has separate defaults: 2 CPUs and 2 GB RAM. Configure it:
container builder start --cpus 8 --memory 32gDefault Configuration
Persist settings in ~/.config/container/config.toml:
[container]cpus = 4memory = "2g"
[build]cpus = 4memory = "8g"rosetta = trueThe [container] section controls per-container defaults. The [build] section controls builder defaults.
Linux Capabilities
Linux capabilities provide fine-grained security control. Apple container starts with a sensible default set:

CAP_AUDIT_WRITECAP_CHOWNCAP_DAC_OVERRIDECAP_FOWNERCAP_FSETIDCAP_KILLCAP_MKNODCAP_NET_BIND_SERVICECAP_NET_RAWCAP_SETFCAPCAP_SETGIDCAP_SETPCAPCAP_SETUIDCAP_SYS_CHROOTAdding Capabilities
container run --cap-add NET_ADMIN my-imageDropping All and Adding Selectively (Least-Privilege)
container run --cap-drop ALL --cap-add SETUID --cap-add SETGID my-imageCapability names are case-insensitive and the CAP_ prefix is optional.
Additional Resource Controls
| Flag | What it does |
|---|---|
--init | Run a lightweight init as PID 1 (signal forwarding, zombie reaping) |
--read-only | Mount root filesystem read-only |
--ulimit nofile=1024 | Set POSIX resource limits (type=soft[:hard]) |
--shm-size 64m | Configure /dev/shm size |
container run \ --cpus 2 \ --memory 2g \ --cap-drop ALL \ --cap-add SETUID \ --cap-add SETGID \ --read-only \ --init \ --name secure-app \ my-imageMonitoring Resource Usage
Verify the limits are applied:
container stats --no-stream my-containerCONTAINER NAME CPU % MEM USAGE / LIMIT PIDSmy-container 2.3% 120.5 MiB / 2.00 GiB 5Summary
In this post, I showed how to manage CPU, memory, and Linux capabilities for Apple containers. The key point is that per-container flags override system defaults, persistent defaults live in config.toml, and capabilities follow a least-privilege model with --cap-drop ALL --cap-add ....
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- π¨βπ» Apple container Resource Management Documentation
- π¨βπ» Linux Capabilities Manual
Oh, and if you found these resources useful, donβt forget to support me by starring the repo on GitHub!
Comments