This error occurs when specifying a tmpfs mount size in an invalid format. Docker expects the size as an integer (bytes) or with proper suffixes like 'k', 'm', or 'g' for kilobytes, megabytes, or gigabytes.
The "invalid tmpfs size" error in Docker indicates that the tmpfs mount size you specified is in an incorrect format. A tmpfs (temporary filesystem) is a RAM-based filesystem that Docker can mount into containers for high-speed temporary storage. Docker requires tmpfs size values to be specified either as plain integers (representing bytes) or with size suffixes. When using Docker Compose v2+, the size must be a pure integer without quotes. The older string notation like "100m" may no longer work in newer versions of Docker Compose, causing this error. This issue commonly appears when migrating from Docker Compose v1 to v2, or when copying configuration examples that use an outdated syntax. The compose-spec requires size to be an integer, but older implementations supported string notation with suffixes.
First, identify where the invalid size is specified. Check your docker run command or docker-compose.yml:
# For docker run, look for --tmpfs or --mount flags
docker run --tmpfs /tmp:size=invalid_value myimage
# For compose files, check tmpfs sections
cat docker-compose.yml | grep -A 5 tmpfsLook for patterns like:
- size: "100m" (quoted string - problematic in v2)
- size: 100m (unquoted string - may not work)
- o: "size=invalid" (invalid format in options)
When using docker run with --tmpfs flag, specify size in the mount options:
# Correct format with size suffix
docker run -d --tmpfs /tmp:size=100m myimage
docker run -d --tmpfs /tmp:rw,noexec,nosuid,size=65536k myimage
# Using --mount flag (recommended)
docker run -d --mount type=tmpfs,destination=/tmp,tmpfs-size=104857600 myimageValid size suffixes for --tmpfs:
- k or K - kilobytes
- m or M - megabytes
- g or G - gigabytes
For --mount flag, use tmpfs-size with bytes or suffixed values.
Docker Compose v2 requires tmpfs size as an integer (bytes). Update your docker-compose.yml:
Wrong (causes error):
services:
myapp:
image: myimage
volumes:
- type: tmpfs
target: /tmp
tmpfs:
size: "100m" # String - will failCorrect (use integer bytes):
services:
myapp:
image: myimage
volumes:
- type: tmpfs
target: /tmp
tmpfs:
size: 104857600 # 100MB in bytes (no quotes!)Common size conversions:
- 64MB = 67108864
- 100MB = 104857600
- 256MB = 268435456
- 512MB = 536870912
- 1GB = 1073741824
- 2GB = 2147483648
Docker Compose also supports a short syntax for tmpfs that allows string suffixes:
services:
myapp:
image: myimage
tmpfs:
- /tmp:size=100m,mode=1777
- /run:size=64mOr as a simple list (uses default size - 50% of host RAM):
services:
myapp:
image: myimage
tmpfs:
- /tmp
- /runThe short syntax tmpfs: at service level handles size differently than the long volumes: syntax.
For reusable tmpfs volumes, create them with proper options:
# Create a 100MB tmpfs volume
docker volume create --driver local \
--opt type=tmpfs \
--opt device=tmpfs \
--opt o=size=100m,uid=1000 \
my_tmpfs_volume
# Use in docker run
docker run -v my_tmpfs_volume:/tmp myimageIn docker-compose.yml with volumes:
volumes:
tmpfs_vol:
driver_opts:
type: tmpfs
device: tmpfs
o: "size=100m" # String allowed here
services:
myapp:
image: myimage
volumes:
- tmpfs_vol:/tmpCheck your Docker and Docker Compose versions to understand which syntax is supported:
docker --version
docker compose version
# or for older standalone compose
docker-compose --versionDocker Compose behavior by version:
- v1 (docker-compose): Supports string notation like "100m"
- v2 (docker compose): Requires integer for tmpfs.size in long syntax
If using Docker Compose v2 and you need string notation, use the short tmpfs: syntax instead of the long volumes: syntax with type: tmpfs.
Understanding tmpfs size defaults: If you don't specify a size, tmpfs defaults to 50% of host RAM. This can be dangerous in production as containers could consume significant memory. Always set explicit size limits.
shm_size vs tmpfs size: Docker also has shm_size for /dev/shm which supports string notation:
services:
myapp:
shm_size: '2gb' # String allowed for shm_sizeCompose spec vs implementation: The compose-spec formally requires size as integer, but implementations vary. Docker Compose v2 strictly follows the spec, while older versions were more lenient.
Debugging compose config: Check what Docker Compose generates:
docker compose configIf you see quoted size values like size: "104857600", that's a bug in compose config output that causes the "must be a integer" error.
Memory considerations: tmpfs uses RAM, so:
- Monitor host memory when using large tmpfs mounts
- Container memory limits (--memory) don't include tmpfs by default
- Multiple containers with large tmpfs can exhaust host memory
Permissions with tmpfs: You may also need to set mode and ownership:
docker run --mount type=tmpfs,destination=/tmp,tmpfs-size=100m,tmpfs-mode=1777 myimagedockerfile 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