docker: Error response from daemon: Minimum memory limit allowed is 6MB means
the value you gave -m (or --memory) is below the floor the engine
accepts. Give it 6m or more; on this engine 6m started and
5m did not.
No container was left behind by the failed run, so there is nothing to clean up. Check
the unit as well, because -m 4m is easy to type when you meant
4g.
The error
docker run --name fix12-dkrun-mem -m 4m alpine true
docker: Error response from daemon: Minimum memory limit allowed is 6MB
Run 'docker run --help' for more information
The exit code was 125. The next script in the test started with this listing, and it
showed no fix12-dkrun-mem:
docker ps -a --filter name=fix12-dkrun --format "{{.Names}} {{.Status}}"
fix12-dkrun-done Exited (0) 24 seconds ago
fix12-dkrun-alp Up 26 seconds
The two names listed were other containers of the same test.
Why it happens
-m sets a hard memory limit for the container, and the message states the
lowest value the engine takes. The two runs on each side of the line show where it is:
-m 5m gave the same message, -m 6m ran true and
exited 0.
The suffix decides the size. With m the limit inside the container read back
as 6291456 bytes, which is 6 times 1024 times 1024, so m means mebibytes. A
limit that small is only good for a test like this one; a real service needs the memory
its process uses, plus headroom.
The fix
docker run --rm -m 6m alpine true
...
docker run --rm -m 6m alpine sh -c "cat /sys/fs/cgroup/memory.max"
6291456
The first command exited 0; the ... stands for the -m 5m run,
which failed as shown above. The second prints the limit the container really got, read
from its cgroup file, which confirms what -m did. For an application, measure
what it uses under load (not run here: docker stats shows a running
container's memory) and size the limit from that, rather than from the minimum.
How it was reproduced
Docker Desktop 4.99.0 on Windows 11, client and engine 29.9.3, runc 1.5.2, the cached
alpine:latest image (Alpine 3.24.2). A PowerShell script ran each command
through cmd /c with stderr merged into stdout, so the commands are shown
without a prompt. Runs: -m 4m and -m 5m failed, -m 6m
succeeded twice, once printing the limit from inside the container. The container names
starting with fix12-dkrun- are the test's own.
Frequently asked
- What is the minimum memory limit for docker run?
- On Docker engine 29.9.3 the message says 6MB. In the test -m 5m was refused and -m 6m started the container and exited normally.
- What unit does docker run -m use?
- The number takes a unit suffix. In the test -m 6m gave the container a limit of 6291456 bytes, which is 6 mebibytes, so m means mebibytes.
- How do I check the memory limit a container got?
- Read its cgroup file from inside the container. In the test docker run --rm -m 6m alpine sh -c "cat /sys/fs/cgroup/memory.max" printed 6291456.
More decoded errors in the Fixes category. For a container that stops at its memory limit, see exited 137 and OOMKilled.