# failed to write to "/sys/fs/cgroup/memory/memory.limit_in_bytes": device or resource busy

- **ID:** `docker/cgroup-memory-limit-exceeded`
- **Domain:** docker
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

Docker daemon runs inside a container or VM with cgroup v1 where the memory limit file is already set by the host cgroup manager, preventing the container from overriding it.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Docker 24.0.7 | active | — | — |
| containerd 1.7.13 | active | — | — |
| Linux 5.15.0 | active | — | — |

## Workarounds

1. **Switch to cgroup v2 by adding 'systemd.unified_cgroup_hierarchy=1' to kernel boot parameters and reboot. Alternatively, set '--cgroup-parent' to a custom path in docker run: docker run --cgroup-parent /docker-custom ...** (85% success)
   ```
   Switch to cgroup v2 by adding 'systemd.unified_cgroup_hierarchy=1' to kernel boot parameters and reboot. Alternatively, set '--cgroup-parent' to a custom path in docker run: docker run --cgroup-parent /docker-custom ...
   ```
2. **Use 'docker run --memory-swap -1' to disable swap limit and avoid writing to memory.limit_in_bytes when memory is already constrained.** (75% success)
   ```
   Use 'docker run --memory-swap -1' to disable swap limit and avoid writing to memory.limit_in_bytes when memory is already constrained.
   ```

## Dead Ends

- **Restart Docker daemon with --exec-opt native.cgroupdriver=systemd** — Cgroup driver mismatch is not the root cause; the error is about cgroup v1 file being busy, not driver incompatibility. (65% fail)
- **Increase memory limit in docker-compose.yml to a very high value** — High memory limit does not resolve the device busy error; the issue is at the cgroup file level, not the limit value. (70% fail)
- **Run container with --privileged flag** — Privileged mode does not bypass cgroup write restrictions; it may even exacerbate cgroup conflicts. (80% fail)
