Tools, FAQ, Tutorials:
Docker Data Storage - "tmpfs" Mounts
How to create a new "tmpfs" mount to a Docker container?
✍: FYIcenter.com
"tmpfs" mounts are stored in the host system’s memory only, and are never written to the host system’s filesystem.
You have two options "--tmpfs" and "--mount" on the "docker container create/run" command to create "tmpfs" mounts.
"--tmpfs" Option - Allows you to mount a "tmpfs" file system to the new Docker container with default configuration.
"--mount type=tmpfs,..." Option - Allows you to mount a "tmpfs" file system to the new Docker container with specific configurations.
For example, the following command "docker run --tmpfs" runs a new container with a new "tmpfs" filesystem mounted at /app.
fyicenter# docker run --tmpfs /app --tty --interactive --detach --name fyi_test alpine fyicenter# docker exec --tty --interactive fyi_test /bin/sh / # df -h Filesystem Size Used Available Use% Mounted on overlay 50.0G 22.3G 27.7G 45% / tmpfs 64.0M 0 64.0M 0% /dev tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup shm 64.0M 0 64.0M 0% /dev/shm tmpfs 3.7G 0 3.7G 0% /app /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /etc/resolv.conf /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /etc/hostname /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /etc/hosts tmpfs 3.7G 0 3.7G 0% /proc/asound tmpfs 3.7G 0 3.7G 0% /proc/acpi tmpfs 64.0M 0 64.0M 0% /proc/kcore tmpfs 64.0M 0 64.0M 0% /proc/keys tmpfs 64.0M 0 64.0M 0% /proc/timer_list tmpfs 64.0M 0 64.0M 0% /proc/sched_debug tmpfs 3.7G 0 3.7G 0% /proc/scsi tmpfs 3.7G 0 3.7G 0% /sys/firmware / # exit fyicenter# docker container stop fyi_test fyi_test fyicenter# docker container rm fyi_test fyi_test
As you can see, the "docker run --tmpfs /app" created a new "tmpfs" filesystem with 3.7G space. The "alpine" Docker has many other "tmpfs" filesystems running the Docker container.
If you want to create new "tmpfs" filesystem with less space, you need to use the "docker run --mount type=tmpfs,destination=..." option as shown below.
fyicenter# docker run --mount type=tmpfs,destination=/app,tmpfs-size=640m \ -tid --name fyi_test alpine fyicenter# docker exec -it fyi_test /bin/sh / # df -h Filesystem Size Used Available Use% Mounted on overlay 50.0G 22.3G 27.7G 45% / tmpfs 64.0M 0 64.0M 0% /dev tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup shm 64.0M 0 64.0M 0% /dev/shm tmpfs 640.0M 0 640.0M 0% /app ... / # exit fyicenter# docker container stop fyi_test fyi_test fyicenter# docker container rm fyi_test fyi_test
Note that data stored in a "tmpfs" filesystem stays with the Docker's container only. When the container is removed, data will removed too.
If you want to keep data files in a "tmpfs" filesystem, you have two options:
⇒ Docker Data Storage - Volume Mounts
⇐ Types of Docker Data Storage
2021-08-15, 2659🔥, 0💬
Popular Posts:
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
How to Build my "sleep" Docker image from the Alpine image? I want the container to sleep for 10 hou...
dev.FYIcenter.com is a Website for software developer looking for software development technologies,...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
Where to find tutorials on Using Azure API Management Publisher Dashboard? Here is a list of tutoria...