skip to Main Content

I want to create tmps volume via docker instructions in dockerfile. Is it possible to do so? Are there additional parameters which I can pass to configure volume instruction?

2

Answers


  1. Here is the Official documentation about how to instrument a tmpfs volume, and here a simple example from there:

    docker run -d 
      -it 
      --name tmptest 
      --mount type=tmpfs,destination=/app 
      nginx:latest
    

    Instead this link tells you how to do the same thing by Docker Compose:

     type: tmpfs
      target: /app
      tmpfs:
        size: 1000
    
    Login or Signup to reply.
  2. In a Dockerfile, you can specify almost nothing about volumes or several other types of runtime configuration. In particular there is no way to indicate a container should always run with a tmpfs mounted.

    The only real Dockerfile statement about volumes at runtime is the VOLUME directive. It has no configuration, only a list of directories that must have some sort of volume mounted on them. Its direct effect is to cause an anonymous volume to be mounted on that directory if nothing else is; its indirect effect is to prevent future RUN directives from modifying the directory. You rarely if ever need it.

    @AntonioPetricca’s answer shows a docker run --mount type=tmpfs option, and if you want to mount a tmpfs container into an container, you must specify this (or a Compose equivalent) when you create it. The target directory does not need to be a VOLUME directory. There is no way to force this option in the Dockerfile.

    In a more limited scope, you can run an individual Dockerfile build step with RUN --mount=type=tmpfs,target=/directory. Again, the named directory won’t be persisted in the image. The mount won’t last beyond that single RUN command though.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search