Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker and "volatile volumes" ala /tmp

Tags:

docker

I run a server with 2 Docker images, one does building and packaging and thus creates alot of shortlived stuff on /tmp.

I'd like this container /tmp to not be backed by persistent volume (union fs or volume) but to use the host's /tmp which in turn is a tmpfs volume and ideal for such operations. Saving access to a normal drive will have overhead and causes access to HDDs (wear-out), I would prefer to try to stay in RAM as much as possible.

Some options are:

  • Bind /tmp/:/tmp to the docker process. Doesnt seem very secure, and problematic if another process accesses this directory
  • Bind a volume to /tmp. This means its on the harddrive unless I manage to move it to /tmp. There is then still the issue of deleting this volume each time the container stops, since Id prefer a clean slate.
  • Mount /tmp as tmpfs in the container. Seems the most sane option. Except that would mean editing all containers instead plainly using existing ones

I am new to Docker, maybe I am missing something obvious.

I search for a way to specify volumes which can or have to be dropped after the container stops. Or even are kept completely in RAM unless this is infeasible. And additionally some easy way to mount /tmp as such a container.

like image 458
Norbert Lange Avatar asked Jan 09 '16 20:01

Norbert Lange


People also ask

Does Docker have tmp?

If you're running Docker on Linux, you have a third option: tmpfs mounts. When you create a container with a tmpfs mount, the container can create files outside the container's writable layer. As opposed to volumes and bind mounts, a tmpfs mount is temporary, and only persisted in the host memory.

Are Docker containers volatile?

If we are normally running the container without any storage definition then the docker data is in a volatile state. In the docker, there are three different ways that the data will be store. Bind mounts: The bind mounts are a very older method to mount the file or the directory to the docker container.

What are the two types of Docker volumes?

Docker volumes are used to persist data from within a Docker container. There are a few different types of Docker volumes: host, anonymous, and, named. Knowing what the difference is and when to use each type can be difficult, but hopefully, I can ease that pain here.

What is volume TMP?

VOLUME /tmp. It explains: We added a VOLUME pointing to "/tmp" because that is where a Spring Boot application creates working directories for Tomcat by default. The effect is to create a temporary file on your host under "/var/lib/docker" and link it to the container under "/tmp".


1 Answers

Docker allows you to do this using the --tmpfs option.

For example;

docker run -it --tmpfs /tmp ubuntu

Or, using the "advanced" --mount syntax, which allows for additional options to be set:

docker run -it --mount type=tmpfs,destination=/tmp ubuntu

For more information, and additional options that can be used, see the "Use tmpfs mounts" section in the documentation.

like image 84
thaJeztah Avatar answered Sep 22 '22 16:09

thaJeztah