1

During initialization of the daemon, docker creates a tmp folder inside its root directory. code reference

What is the exact purpose of this tmp directory, does that directory is only used to store temporary files related to docker, if yes does it only used in docker startup? Do containers also have access to that directory and use it to store their temporary files? Does it also cache some data for the next reboot of the host machine?

The prime objective to get this information is to estimate the size of the tmp directory and create a strategy for storing it.

I tried looking for the information in official docs, but I wasn't able to find any. There is a question here regarding /tmp folder strategy, but this will only help me once I know what exactly tmp is used for.

bruce
  • 36
  • 4
  • 1
    The name /tmp implies that there is no reason to actively manage and store it. By convention, everything should function even when it's empty. In the code you linked, you also see that its content is purged, when the daemon starts, I guess. The /tmp folder of an individual container is separate from this, just like every other dir and file in the container, as this relies on namespaces. See https://stackoverflow.com/questions/34820558/difference-between-cgroups-and-namespaces. This one is also helpful to understand more https://youtu.be/MHv6cWjvQjM – The Fool Mar 31 '22 at 05:41
  • @TheFool - Thanks for the references. I get your point that containers have their own different namespace, so there is no way it can have access to docker tmp. But still, my question is what is the purpose of having it, then, is it used by docker anywhere during the whole process of its startup and starting a container? – bruce Mar 31 '22 at 06:12
  • I don't know what it puts there are, but it's fairly common for programs to produce some temporary files. I guess you could just take a look inside. Have you tried that already? – The Fool Mar 31 '22 at 06:26
  • Yes, I had a look in there. But there it was empty as expected, maybe because it had created some files in the past and deleted them. One more thing I want to know is how big it can get in the usual scenario if we are dealing with a space issue. – bruce Mar 31 '22 at 07:07
  • If nothing else, I know the Docker build context is stored there during `docker build` commands (see various `/var/lib/docker/tmp/...: not found` errors when you `COPY` a file that doesn't exist). This doesn't seem like a programming-related question, though? – David Maze Mar 31 '22 at 11:08

0 Answers0