October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Limit CPU, Memory, and Filesystem Access for Agents in Docker

Set hard CPU and memory ceilings for Docker agents, choose an intentional swap policy, and expose only the host files they need through carefully scoped mounts.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Docker’s CPU and memory flags to put explicit resource ceilings on an agent, then control its host-file access separately with narrowly scoped mounts. A practical baseline is --cpus for a hard CPU cap, --memory for a hard memory limit, read-only mounts for inputs, and a dedicated writable location only where the agent must save output. These controls depend on host kernel and cgroup support; they do not make an unrestricted Docker daemon safe to expose.

Start with the right Docker controls

Docker documents that, by default, a container has no resource constraints and can use as much of a resource as the host kernel scheduler allows. Resource limits and filesystem permissions solve different problems: CPU and memory flags do not restrict which host files a mounted path exposes, while a read-only mount does not limit resource use.

As an Amazon Associate I earn from qualifying purchases.

The examples below use docker run. Replace agent-image with your image and adjust paths and limits to the workload. No single CPU or memory value is appropriate for every agent; measure the workload and leave host headroom.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a CPU ceiling or restrict core placement

Use --cpus for a hard ceiling

For most workloads, --cpus is the straightforward way to limit CPU time:

#1 Best Overall
HP EliteDesk 800 G2 Desktop Mini Business PC, Intel Quad-Core i5-6500T up to 3.1G, 16GB DDR4, 240GB SSD, VGA, DP, Win 11 Pro 64 bit (Renewed)
  • This Certified Refurbished product is tested and certified to look and work like new. The refurbishing process includes functionality testing, basic cleaning, inspection, and repackaging. The product ships with all relevant accessories, a minimum 90-day warranty, and may arrive in a generic box. Only select sellers who maintain a high performance bar may offer Certified Refurbished products on Amazon.com
  • Intel Quad-core i5-6500T up to 3.1G,16G DDR4 memory(2 slots,supports up to 32GB),240G SSD
  • Includes USB Keyboard(English Keyboard & Mouse Included)
  • I/O ports:Front:2 USB 3.0 ,microphone,headphone ,USB Type-C port Rear:4USB 3.0 ,VGA DP port,RJ-45
  • Operating System:Win10Pro64bit
docker run --cpus="1.5" agent-image

Docker’s documented example says that on a two-CPU host, this setting allows the container to use at most 1.5 CPUs. It corresponds to a CPU period of 100,000 microseconds and a quota of 150,000 microseconds. The period normally stays at its 100,000-microsecond default; the quota is the time allowance before the scheduler throttles the container. You can set the underlying values directly with --cpu-period and --cpu-quota, but usually do not need to.

Use --cpuset-cpus to choose eligible cores

Core affinity controls where the container may run, not its overall CPU percentage. For example, --cpuset-cpus="0-3" permits cores 0 through 3, while --cpuset-cpus="1,3" permits cores 1 and 3. Use affinity when placement matters; combine it with --cpus if you also need a hard ceiling.

Do not treat CPU shares as a cap

--cpu-shares assigns a relative weight when containers compete for CPU. It affects priority under contention, but does not reserve a fixed amount or prevent a container from using spare CPU cycles. Choose --cpus when you need a ceiling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set memory and decide how swap should work

Apply a hard memory limit

Use --memory (or -m) to set the container’s maximum memory allowance:

Rank #2
Beelink SER3 Mini PC AMD Ryzen 3 3200U (up to 3.5GHz), 8GB DDR4 480GB PCIE3.0 SSD Mini Computer, Radeon Vega 3 Graphics,1000Mbps LAN, Dual HDMI 4K Display Home-Office PC
  • 【SER3 Next-Gen Light Office Mini PC】Beelink Mini pc New SER3 AMD Ryzen 3 3200U Processor (2.6-3.5GHz 2C/4T),with Radeon Vega 3 Graphics 3core 1200 MHz, Light office, 4K multimedia playback, virtual machine, NAS, meeting all your daily needs, Beelink mini pc is only 4.88 x 4.44 x 1.65 inches and takes up only 1/40
  • 【8GB DDR4 RAM+ 480GB PCIe3.0 SSD】SER3 Beelink mini pc comes with 8GB SODIMM DDR4 memory, dual-channel memory expansion slots supports up to 32GB (2x16GB) expansion, you can also replace the 480GB SSD up to 2TB (excluded) M.2 PCIE3.0 x4(2280) slot (Incompatible with SATA3 SSDs), or add a 2.5inch 7mm HDD(max 2TB, excluded) to expand the storage. Large capacity brings quicker load times across your entire catalogue of apps and programs
  • 【USB3.2 + WiFi 5 + BT 5.0】Beelink AMD Ryzen 3 3200U Mini Desktop Computer is equipped with rich interfaces: USB3.2x4, HDMI x2, 1000M LANx1. The transmission rate of USB3.2 is up to 10Gbps, 21 times faster than USB2.0. WiFi 5 (802.11ac) Bluetooth5.0 lower latency , more stable and efficient to connect to multiple wireless devices such as projector, printer, monitor, speakers and etc
  • 【Improve Work Efficiency】SER3 Dual HDMI prots allow you to expand your viewing area to enjoy better experience and multi-task easily, i.e. web browsing, design, 4K videos playback, online class, perfectly valid as a multimedia center to use KODI, IPTV or use as a digital signage and brings true-to-life 4K@60Hz visual feat to the audiance
  • 【Why Beelink Mini PC】Beelink SER3 VESA mount can hide the micro pc behind a monitor or HDTV like an all-in-one pc, free you from messy desktop, Cooling system Large fan and dual heat conduction tube,make heat dissipation more efficient,3200U Mini desktop pc also supports Wake On LAN, RTC Wake, Auto Power On, a great to use as a server for media (Plex or FTP)
docker run --memory="2g" agent-image

The value here is an example, not a recommended agent size. Docker documents a minimum accepted memory setting of 6 MB, but a valid minimum is not a practical sizing guide. Measure the agent’s working set under representative use and allow enough headroom for the host and other workloads.

Use a reservation only as a soft threshold

--memory-reservation is a soft limit that applies under memory pressure; it is not a promise that usage will remain below that amount. Set it lower than --memory for the reservation to take precedence. For example:

docker run --memory="2g" --memory-reservation="1g" agent-image

Understand the combined memory-and-swap allowance

--memory-swap only has meaning when paired with --memory. A positive value sets the combined memory-plus-swap allowance, not an additional amount of swap. Setting it equal to the memory limit disables swap for the container. If omitted, Docker documents that the container may use swap up to the memory limit in addition to RAM, when host swap is available. A value of zero is treated as unset. Frequent swapping can slow an agent substantially, so choose based on whether you prefer more time to recover under pressure or stricter memory behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not use free inside a container as proof of its own swap allowance: it reports host swap, not a reliable container-specific limit.

Rank #3
HP EliteDesk 800 G4 Mini Tiny Business PC, Intel Hexa-Core i5-8500T up to 3.5GHz, 16GB DDR4 RAM, 256GB NVMe SSD, Dual Monitor Support, WiFi, Bluetooth, HDMI, DisplayPort, Windows 11 64-bit (Renewed)
  • Powerful Performance: Intel Core i5 Hexa Core processor for reliable multitasking and smooth computing.
  • Fast & Efficient: 16GB DDR4 RAM and 250GB SSD for quick startup and performance.
  • Windows 11 Pro: Modern operating system with professional-grade tools and enhanced security.
  • Compact Design: Space-saving mini chassis fits neatly on or under your desk.
  • Renewed Quality: Professionally tested and renewed to perform like new; may show minor cosmetic wear.

Plan for out-of-memory kills

On Linux, when memory is insufficient, the kernel may kill processes. Test the agent’s actual memory needs and size the host and container budget accordingly. Docker warns against disabling OOM killing without also setting a memory limit; disabling it is not a substitute for a defined budget.

Control filesystem access with mounts

Expose only the paths the agent needs

A bind mount gives the container access to a host path and is writable by default. Processes in the container can modify or delete files within a writable mounted path. Avoid broad mounts such as the host root; mount only a specific input or output directory.

For input that should not be changed, mark the mount read-only:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker run 
  --mount type=bind,source="$PWD/input",target=/input,readonly 
  agent-image

The agent can read files under /input but cannot write through that mount. A read-only mount narrows this exposure; it does not isolate the container from every other attack surface.

Choose storage based on persistence and host access

Storage Can the container write? Persists after container stops or is removed? Direct host path access
Bind mount Yes by default; use readonly or ro for read-only access. Host files remain; the mount itself does not define a separate persistence lifecycle. Yes, it maps a specified host path.
Docker volume Yes by default; volumes can also be mounted read-only. Designed for persistent data; lifecycle is managed by Docker. Not as a directly specified host path; Docker manages where volume data resides.
tmpfs Yes, while mounted. No. Data disappears when the container stops or restarts, or the host reboots. No persistent host directory is shared.

Use a volume for persistent or write-intensive container data, a bind mount when direct host/container file sharing is needed, and tmpfs for temporary state that must not persist. If the agent only needs to read a mounted volume, mount it read-only as well.

Make the container filesystem read-only where practical

For a stricter baseline, make the container’s root filesystem read-only if the application supports it, then add narrowly scoped writable locations for required output, cache, or temporary state. Keep inputs read-only and avoid exposing sensitive host directories unnecessarily. Applications that expect to write into their root filesystem may need explicit writable mounts to run correctly.

On Docker Desktop, the daemon runs inside a Linux VM, so a bind mount refers to a path made available to that daemon rather than directly exposing the entire host filesystem. Bind mounts are created on the daemon host; account for that distinction when interpreting host paths.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Combine limits and least-access mounts

This example gives an agent a 1.5-CPU ceiling and a 2 GB memory ceiling, makes its input read-only, and provides a separate writable output directory:

Best Value
Beelink Me Pro, Mini PC NAS, Intel N150 CPU, 16GB LPDDR5, 1TB SSD, 3*M.2 PCIe3.0 SSD Slots + 2*HDD Bays(MAX 72TB), 5G + 2.5G Dual LAN/WiFi6/BT5.4, 4K Media Library, Private Cloud, Soft Router
  • 【Hybrid 2-Bay Storage: NAS & Mini PC in One】Beelink ME Pro features two 3.5"/2.5" SATA HDD slots and three M.2 PCIe3.0 SSD slots (pre-installed with a 1TB system drive) supporting a massive 72TB expansion. it’s the ultimate solution for building a massive private cloud, automated backups, or a centralized media library
  • 【Next-Gen Intel N150 & 16GB LPDDR5】 Powered by the Intel N150 processor (up to 3.6GHz, max 25W TDP) and 16GB LPDDR5 4800MT/s RAM, this mini pc delivers efficient multitasking and smooth performance for home office, virtualization, and server tasks with lower power consumption
  • 【5GbE + 2.5GbE High-Speed Dual Networking】 Equipped with 5G & 2.5G Ethernet ports, this Dual LAN Mini PC supports network aggregation and high-speed data transfer. Ideal for stable, lag-free access to your files, high-speed downloading, and advanced networking configurations like soft routing
  • 【Swappable Modular Motherboard】The innovative DlY drawer-style design supports easy motherboard upgrades, compatible with Intel N-series, Intel 12th/13th/14th/15th Gen, AMD FP8 series, and ARM architectures
  • 【Easy Dust Cleaning】Simply slide out the motherboard for quick maintenance
docker run --rm 
  --cpus="1.5" 
  --memory="2g" 
  --mount type=bind,source="$PWD/input",target=/input,readonly 
  --mount type=bind,source="$PWD/output",target=/output 
  agent-image

These numbers are illustrative. Create the output directory first, and grant the agent only the write access its task requires. Add a memory reservation or explicit swap policy only after deciding how the workload should behave under memory pressure.

Verify that limits are enforceable on the host

Docker’s resource controls depend on kernel support. Check docker info for warnings if a limit is not behaving as expected. In rootless Docker, Docker’s guidance says cgroup-related resource flags such as --cpus and --memory require cgroup v2 and systemd. Without those prerequisites, do not assume the flags provide the intended enforcement.

Namespaces isolate process and network views, while cgroups account for and limit resources; neither makes access to the Docker daemon harmless. A user who can control the daemon may be able to create containers with host filesystem access. Protect daemon/API access and validate container parameters, especially when a service accepts requests to launch agent workloads.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Docker’s agent sandbox is a separate feature

Docker also documents a docker sbx create command for its agent sandbox feature, with CPU and memory sizing and workspace options such as omitting a workspace bind mount or using a read-only private clone. These options belong to that feature and should not be assumed to exist in every Docker Engine installation. Check the command’s availability and current behavior in Docker’s documentation before building a workflow around it.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.