Demonstrate how to use tmpfs
with Docker.
tmpfs
is a ramdisk that only works on Docker linux.
# allocate and show size inside container
docker run -it --rm --mount type=tmpfs,destination=/tempdisk,tmpfs-size=2m alpine:latest /bin/df -h /tempdisk
# allocate space above size of disk (no space left on device)
docker run -it --rm --mount type=tmpfs,destination=/tempdisk,tmpfs-mode=770,tmpfs-size=4m alpine:latest /usr/bin/fallocate -l 5M /tempdisk/my.test
# mount share
docker run -it --rm --mount type=tmpfs,destination=/tempdisk,tmpfs-mode=770,tmpfs-size=4m alpine:latest /bin/sh
# show size of share
df -h
Mount using --tmpfs
# size seems to be max available
docker run --rm -it --tmpfs /tempdisk alpine:latest /bin/sh
# NOTE: Use `df -h` on the host to see allocations
# show size of share is max size of memory
df -h
# on host use free
free
# in the container allocate some tmpfs space
/usr/bin/fallocate -l 100M /tempdisk/my.test
ls -la /tempdisk/my.test
# on host use free again
free
tmpfs
also honours the configured max memory limits
# allocate and show size inside container
docker run -it --rm --memory=100m --mount type=tmpfs,destination=/tempdisk,tmpfs-size=600m alpine:latest /bin/sh
# in the container allocate some tmpfs space (it will fail)
/usr/bin/fallocate -l 150M /tempdisk/my.test
# size seems to be max available
docker run --rm -it --memory=100m --tmpfs /tempdisk alpine:latest /bin/sh
# in the container allocate some tmpfs space (it will fail)
/usr/bin/fallocate -l 150M /tempdisk/my.test