Feedback

Chat Icon

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Docker Volumes & Data Management
42%

TMPFS Mounts

If you need to persist data between the host machine and containers, you should use Docker volumes or bind mounts. However, in cases where you don't need to write files to the container's writable layers, TMPFS mounts can be a suitable option. TMPFS mounts store data in the host's memory, and when the container stops, the TMPFS data is completely removed. This approach is useful for scenarios like passing sensitive files to containers where persistence isn't required, due to the ephemeral nature of these files. Let's explore creating a TMPFS volume for an Nginx container. There are two different methods to achieve this.

1) Use the --mount flag.

docker run -d \
  -it \
  --name nginx_with_tmpfs_volume_1 \
  --mount type=tmpfs,destination=/secrets \
  nginx

1) Use the --tmpfs flag.

docker run -d \
  -it \
  --name nginx_with_tmpfs_volume_2 \
  --tmpfs /secrets \
  nginx

When creating a tmpfs, you can specify options like tmpfs-size and tmpfs-mode.

OptionDescription
tmpfs-sizeSize of the tmpfs mount in bytes. Unlimited by default.
tmpfs-modeFile mode of the tmpfs in octal. For instance, 700

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Enroll now to unlock all content and receive all future updates for free.

Unlock now  $31.99$25.59

Hurry! This limited time offer ends in:

To redeem this offer, copy the coupon code below and apply it at checkout:

Learn More