Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Data Persistence tmpfs Mounts Inmemory Temporary
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-data-persistence-tmpfs-mounts-inmemory-temporary

Docker Docker Data Persistence tmpfs Mounts Inmemory Temporary

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~3 min read

1. Core Command / Concept

tmpfs mounts provide in-memory, temporary storage for Docker containers. docker run -it --tmpfs /tmp:rw.

2. Step-by-Step

  1. Check if tmpfs is enabled on your system: docker info | grep "Total Memory"
  2. Create a new container with tmpfs mount: docker run -it --tmpfs /tmp:rw --name tmpfs-test ubuntu /bin/bash
  3. Verify tmpfs mount: df -h | grep tmpfs
  4. ⚠️ Delete the container: docker rm -f tmpfs-test
  5. Clean up tmpfs mount: docker system prune -f

3. Real Commands with Examples


Example 1: Temporary Storage

Purpose: Create a temporary storage for a container.
Command: docker run -it --tmpfs /tmp:rw --name tmpfs-test ubuntu /bin/bash Flags: -it for interactive shell, --tmpfs /tmp:rw for tmpfs mount.

Example 2: Persistent Storage

Purpose: Create a persistent storage for a container.
Command: docker run -it --mount type=tmpfs,destination=/tmp,ro --name tmpfs-test ubuntu /bin/bash Flags: --mount for tmpfs mount, ro for read-only.

Example 3: Large Tmpfs Mount

Purpose: Create a large tmpfs mount for a container.
Command: docker run -it --tmpfs /tmp:rw,size=2g --name tmpfs-test ubuntu /bin/bash Flags: size=2g for 2GB tmpfs mount.

4. Common Errors


Error 1: Tmpfs Mount Not Found

Error message: docker: Error response from daemon: failed to mount local volume: mount /tmp: mountpoint is not a directory.
Why it happens: Tmpfs mount is not a directory.
Fix: docker run -it --tmpfs /tmp:rw --name tmpfs-test ubuntu /bin/bash

Error 2: Insufficient Memory

Error message: docker: Error response from daemon: failed to mount local volume: mount /tmp: out of memory.
Why it happens: Insufficient memory for tmpfs mount.
Fix: docker run -it --tmpfs /tmp:rw,size=2g --name tmpfs-test ubuntu /bin/bash

Error 3: Tmpfs Mount Not Persistent

Error message: docker: Error response from daemon: failed to mount local volume: mount /tmp: mountpoint is not a directory.
Why it happens: Tmpfs mount is not persistent.
Fix: docker run -it --mount type=tmpfs,destination=/tmp,ro --name tmpfs-test ubuntu /bin/bash

5. Quick Checks


Scenario 1: Tmpfs Mount Enabled

Situation: Check if tmpfs is enabled on your system.
Command: docker info | grep "Total Memory" Correct response: Total Memory: 16.00 MB

Scenario 2: Tmpfs Mount Created

Situation: Check if tmpfs mount is created.
Command: docker inspect --format='{{.Mounts}}' tmpfs-test Correct response: [{Name:tmpfs,Mountpoint:/tmp,Source:/dev/zero,Type:tmpfs,Options:rw}]

Scenario 3: Tmpfs Mount Deleted

Situation: Check if tmpfs mount is deleted.
Command: docker inspect --format='{{.Mounts}}' tmpfs-test Correct response: []

6. Last-Minute Reference

  • --tmpfs flag mounts tmpfs on the container.
  • :rw flag mounts tmpfs in read-write mode.
  • size flag sets the size of the tmpfs mount.
  • --mount flag mounts a tmpfs volume.
  • ro flag mounts tmpfs in read-only mode.
  • docker info command displays system information.
  • docker inspect command displays container information.
  • docker system prune command removes unused containers.
  • ⚠️ docker rm -f command deletes a container without prompt.
  • ⚠️ docker system prune -f command removes all unused containers without prompt.
  • ? Verify with 'docker version' for Docker version.


ADVERTISEMENT