containous / traefik-library-image

ARCHIVED
https://github.com/traefik/traefik-library-image
Apache License 2.0
218 stars 60 forks source link

Volume at /tmp #45

Closed fthorns closed 5 years ago

fthorns commented 5 years ago

Hi there,

the Dockerfile requests a volume to be mounted at /tmp. In case no volume is explicitly mounted when the container is started, Docker creates a new volume every time the container is created. Since the documentation does not advice to mount a volume to /tmp, it seems that this volume is not needed. It would be great if someone could confirm that there is no need for the /tmp volume and drop the VOLUME clauses from the Dockerfiles.

Regards,

Fabian

ldez commented 5 years ago

Hi, the /tmp folder is required by some middlewares (ex: buffering)

fthorns commented 5 years ago

Hi, thanks for the explanation. Would it be generally advisable to put /tmp/ on a persistent volume? Right now it seems that the volumes are not reused in any of the documentation's examples, so the data could as well just stay in the ephemeral storage of the container. The current documentation leads to a huge number of orphaned volumes over time, so it might be worth to either drop the volume or advice handling it correctly. Not sure which way is the preferable one, though.

Fabian

gbouthenot commented 5 years ago

I agree with fthorns: Either this volume should be removed from the Dockerfile, or the documentation should explicitely specify it should me mapped.

errm commented 5 years ago

Would it be generally advisable to put /tmp/ on a persistent volume

I don't think this is required...

could as well just stay in the ephemeral storage of the container

This could cause a performance issues... so using a volume is preferable I think...

Perhaps we could just add some documentation mentioning which middlewares needs this facility ... then it's simple to mount tmpfs or some other storage where required...

fthorns commented 5 years ago

could as well just stay in the ephemeral storage of the container

This could cause a performance issues... so using a volume is preferable I think...

Perhaps we could just add some documentation mentioning which middlewares needs this facility ... then it's simple to mount tmpfs or some other storage where required...

If it boosts performance for certain middlewares it might be worth documenting it as a tuning tip (it's still possible to mount a volume to any path, even without the path being explicitly declared in the Dockerfile). If the user is aware of the volume they might even consider preserving it across container restart to avoid building up the cache over and over again.

dtomcej commented 5 years ago

The buffering middleware is an example of why this volume is needed.

If there is no /tmp directory, the buffering middleware will fail. We generate this volume to ensure that the directory is present due to being based off a scratch image.

We had a choice to make a bare directory or a volume for this, and we chose to make a volume due to flexibility and giving more options to operators.

BashfulBandit commented 5 years ago

We had a choice to make a bare directory or a volume for this, and we chose to make a volume due to flexibility and giving more options to operators.

Is this documented anywhere? I found a large list of empty Docker Volumes in my Docker Swarm today and found my Traefik service was the one creating these every time it was restarted.

With that said, is there any need to have the /tmp directory be persistent between restarts? This use of the VOLUME instruction doesn't seem to be the correct use in this case.

dduportal commented 5 years ago

Hi, The usage of the VOLUME instruction in a Dockerfile is really different than the kind of "mount" to be used:

From these theoretical concerns, a few tasks should be done:

About advertising "how to handle" these volumes, it's a complicated topic, as it is a general matter to ALL projects using Docker containers. Should Traefik's project tell its user how to use Docker? This would be a huge effort, and would lead to a never-up-to-date documentation right? However, it's open source, do not hesitate to propose a change in the doc, understanding that the community of maintainers will have to carry such a change ("No is temporary, Yes is definitive").

polarathene commented 5 years ago

Is this behaviour only related to the scratch base image or alpine too?

Just to confirm, this is enforced because it avoids extra steps by the user to ensure they're mounting tmpfs?

Is there a way for a user to override the approach here that still works but avoids creating anonymous volumes each time? I'm pretty sure I've used a container in the past that would write to /tmp on the host but it wasn't piling up anonymous containers mentioned here :/

dduportal commented 5 years ago

@polarathene , the behavior is the same for both images, because of the use of instruction "VOLUME" in both Dockerfiles.

You can definitively avoid anonymous volumes by providing a name for each mountpoint:

docker run -v tmp-for-traefik:/tmp .... traefik

But again, you strongly should run a docker system prune -f --volumes everyday to cleanup dangling images, anonymous volumes, unused networks, so you keep your Docker engine clean and lean.

rlagutinhub commented 5 years ago

I want use tmp disk in memory (tmpfs). What max size can be for this tmp disk? and what will happen if out free space?