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, 2822🔥, 0💬
Popular Posts:
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
How To Access a Global Variable inside a Function? in PHP? By default, global variables are not acce...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...
Can You Add Values to an Array without Keys in PHP? Can You Add Values to an Array with a Key? The a...