This error occurs when you try to set a container memory limit below Docker's minimum threshold of 6MB. The fix is straightforward: increase the memory limit to at least 6MB or remove the constraint entirely if no limit is needed.
The "Minimum memory limit allowed is 6MB" error occurs when you attempt to create or run a Docker container with a memory limit (`--memory` or `-m` flag) set below 6 megabytes. Docker enforces this minimum because container runtimes like runc require a baseline amount of memory just to start a container, before any application code even runs. This minimum was raised from 4MB to 6MB in Docker Engine 20.10 (tracked in moby/moby#41168) to account for higher memory usage by modern container runtimes during startup. The limit applies to any memory constraint you set, whether via the Docker CLI, Docker Compose, or container orchestration tools. If you don't specify a memory limit, containers have no restriction and can use as much memory as the host kernel allows. The error only appears when you explicitly set a limit below the threshold.
First, find where the low memory limit is being set. Check your Docker command or configuration:
# If using docker run directly, check your command for -m or --memory flags
docker run --memory=4m myimage # This will fail
# Check Docker Compose files for memory settings
grep -r "memory:" docker-compose*.ymlLook for any memory values below 6MB (6m, 6000000 bytes, or 0.006g).
Update your memory limit to 6MB or higher:
Docker CLI:
# Minimum valid memory limit
docker run --memory=6m myimage
# A more practical limit for most applications
docker run --memory=64m myimageDocker Compose (v3 with deploy):
services:
myapp:
image: myimage
deploy:
resources:
limits:
memory: 64M
reservations:
memory: 32MDocker Compose (v2 syntax):
services:
myapp:
image: myimage
mem_limit: 64m
mem_reservation: 32mMemory unit suffixes: b (bytes), k (kilobytes), m (megabytes), g (gigabytes).
If you don't actually need to constrain memory, simply remove the limit:
Docker CLI:
# No memory limit - container uses available host memory
docker run myimageDocker Compose:
services:
myapp:
image: myimage
# Remove any memory-related fields:
# - mem_limit
# - memory
# - deploy.resources.limits.memoryBy default, containers have no memory constraints and can use as much memory as the host allows.
If you're creating containers programmatically, ensure memory is specified correctly:
Docker SDK for Python:
import docker
client = docker.from_env()
# Memory in bytes - must be at least 6MB (6291456 bytes)
container = client.containers.run(
"myimage",
mem_limit="64m" # Use string with unit suffix
)Docker API (direct HTTP):
curl -X POST "http://localhost:2375/containers/create" \
-H "Content-Type: application/json" \
-d '{"Image": "myimage", "HostConfig": {"Memory": 67108864}}'The Memory value is in bytes. 6291456 bytes = 6MB minimum.
spotify/docker-client (Java):
// Memory in bytes
HostConfig hostConfig = HostConfig.builder()
.memory(67108864L) // 64MB in bytes
.build();For Kubernetes deployments, ensure pod memory limits are at least 6Mi:
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: myimage
resources:
limits:
memory: "64Mi" # Must be >= 6Mi
requests:
memory: "32Mi"Note: Kubernetes uses binary units (Mi = mebibytes), while Docker uses decimal (m = megabytes). 6Mi is slightly more than 6m.
For very small containers, consider if you really need such tight limits. Most applications need significantly more than 6MB to run effectively.
Why 6MB minimum? Docker raised the minimum memory limit from 4MB to 6MB in Docker Engine 20.10 to account for increased memory usage by container runtimes (runc, containerd) during container startup. Even before your application code runs, the runtime needs memory for process initialization, namespace setup, and cgroup configuration.
Historical context: If you have older Docker configurations or scripts that used 4MB limits, they will break when upgrading to Docker 20.10+. Update these to at least 6MB.
Memory limit vs. memory reservation:
- --memory / mem_limit: Hard limit - container cannot exceed this
- --memory-reservation / mem_reservation: Soft limit - Docker tries to maintain but can exceed under memory pressure
Practical minimums by application type:
- Static file server (nginx): 32-64MB
- Node.js application: 128-256MB
- Java application: 256MB-1GB (JVM overhead)
- Python/Ruby application: 64-256MB
Testing with minimal containers: If you're experimenting with minimal memory limits for testing purposes, consider using the --memory-swap flag to allow some flexibility:
docker run --memory=6m --memory-swap=12m myimageThis allows 6MB RAM + 6MB swap for a total of 12MB.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec