Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Local Volume Driver options

I am creating docker volume using docker local volume driver but docker documentation has limited information about what options are available like below. How do I know what options I should use and what are the options available.

docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 foo

like image 737
piyush goel Avatar asked Jun 06 '20 13:06

piyush goel


2 Answers

If you're using --driver local (the default), they're the standard Linux mount(8) options. In most cases you don't need any at all; it is sufficient to just run

docker volume create foo

or the equivalent Docker Compose

volumes:
  foo:

The only particularly notable option for routine use is that setting --opt o=bind --opt device=/some/source/dir uses Linux mount options to create a bind mount in a Docker named volume. This is very similar to the shorter Docker -v /some/source/dir:/container/dir bind-mount syntax.

like image 120
David Maze Avatar answered Oct 16 '22 18:10

David Maze


Based on the answer by @DavidMaze and other comments on the answer.

The local Driver has options that is platform dependent. As for the Docker Docs

The built-in local driver on Windows does not support any options.

The built-in local driver on Linux accepts options similar to the linux mount command. You can provide multiple options by passing the --opt flag multiple times.

But if you using WSL 2 Backend for Docker in Docker for Windows there is a chance these options for linux might work.

You can view options supported by Linux mount command through here mount(8) — Linux manual page

You can pass these options to the Docker CLI using the --opt flag as follows

docker volume create --driver local \
--opt type=tmpfs \
--opt device=tmpfs \
--opt o=size=100m,uid=1000 \
foo

This creates a tmpfs volume called foo with a size of 100 megabyte and uid of 1000

The same can be achieved in Docker Compose as follows

Docker Compose File v3

volumes:
  foo:
    driver: local
    driver_opts:
      type: "tmpfs"
      o: "o=size=100m,uid=1000"
      device: "tmpfs"

There are also additional Filesystem specific mount options that might be helpful for you. FILESYSTEM-SPECIFIC MOUNT OPTIONS

References:

  • docker volume create - Driver-specific options
  • Docker Compose File v3 - Volume configuration reference
like image 5
Missaka Iddamalgoda Avatar answered Oct 16 '22 16:10

Missaka Iddamalgoda