Are docker artifacts when running a container stored in the host file system or in memory?

Context

I write rails applications by caching a fragment of a page in production (saving the html result of a certain fragment to avoid rebuilding it).

The usual way to do this is to save the fragment in memcache or redis. The default caching option in rails is to use FS caching (saving a fragment as a file), since it has the advantage of having no dependencies (you do not need to configure memcache or redis). This is a less popular option because it is slower than memory caching, and you must clear your cache manually, while you can rely on old keys that will be automatically cleared using memcache or properly configured redis.

Question

After using dockers for some time, I understand that clearing previous cache files is no longer a problem: when deploying, a new container starts, automatically discarding all previous cache files. This is probably slower than memory usage, of course, but it has the advantage of not requiring any configuration, which is pretty cool when loading fast side projects.

But then I ask myself: does fs actually write to fs in the container, or does it write to RAM instead? This is troubling, as it will mean that using it can very quickly saturate RAM, especially with many projects on the same server.

+5
source share
1 answer

In this case, Docker does everything the process does. Docker is just a fancy way to start a process, not a traditional virtual machine. You probably know this, but I'm just repeating to lay the foundation for my answer. Docker obeys what your process wants to do. If you specify that you want your process to use the file system cache on disk, and this process writes to the cache, Docker will not store this result in memory. It will write to the cache on disk. You are correct that ephemeral containers have advantages, as you mentioned here, when clearing the file cache when creating a new container.

When your process writes to disk, Docker writes it to a special UnionFS (which can use one of several different back-end storage, such as aufs or btrfs, there are several options). Docker uses this β€œspecial” file system for two reasons: to avoid duplicating files from the same base image and to highlight file system changes specific to your process from common layers of the base image. The specific term for the copy-on-write mechanism. The fact is that when Docker says that he writes to the file system what Docker does. He does not write the material to memory and acts as the material is written to the file system: he actually writes the material to disk. The topic of storage drivers is deep and complex, but the documentation for this material is well written and accurate, as is the case for all docker documentation in general. Be sure though there is no magic in your process. You can safely assume that Docker does what it says it does.

+3
source

Source: https://habr.com/ru/post/1242697/


All Articles