Sign inSign up

ashald/docker-volume-loopback

By ashald

Updated over 7 years ago

Docker Volume Driver providing fixed size volumes using loopback devices

Plugin
0

10K+

ashald/docker-volume-loopback repository overview

Overview

The docker-volume-loopback is a Docker volume driver that allows creating volumes that are fixed in size. Fixed size volumes are valuable because they can be used to "reserve" disk space for a particular container and make sure it will be available later when needed or limit the disk space available to a container so that it won't abuse the host and affect other processes running there.

This plugin makes use of Linux loop devices that can be used to present a file on a filesystem as a regular block device. Using loop devices allow for great flexibility as there are next to 0 prerequisites and they can be used on arbitrary Linux hosts. Volumes themselves are stored as regular files and are very easy to manage or even can be moved between different hosts. All of that being said, there are some potential performance and durability implications one may need to take into account when using loop devices and this particular plugin.

More details: https://github.com/ashald/docker-volume-loopback

Installation

Automatic

Plugin is compatible with [Docker's managed plugin system] and therefore can be installed as simple as:

$ docker plugin install ashald/docker-volume-loopback
  Plugin "ashald/docker-volume-loopback" is requesting the following privileges:
   - mount: [/dev]
   - mount: [/]
   - allow-all-devices: [true]
   - capabilities: [CAP_SYS_ADMIN]
  Do you grant the above permissions? [y/N] y
  latest: Pulling from ashald/docker-volume-loopback
  ...
  Installed plugin ashald/docker-volume-loopback
Manual

Plugin can be run "manually" - just as an executable on the same host as Docker daemon. Plugin default options are such that it should be possible to run it with minimum or no configuration. Plugin itself does not talk to Docker but it's the other way around - [Docker expects to find plugin's socket in one of few pre-defined locations].

Configuration

Regardless of the way plugin is installed certain aspects of its behavior can be controlled. Both command line arguments and environment variables are supported.

Env VarArgumentDefaultComment
DATA_DIR--data-dir/var/lib/docker-volume-loopbackPersistent dir to store volumes' data
MOUNT_DIR--mount-dir/mntDir to mount volumes so Docker can access them
STATE_DIR--state-dir/run/docker-volume-loopbackVolatile dir to keep track of currently used volumes
LOG_LEVEL--log-level20-4 for error/warning/info/debug/trace
LOG_FORMAT--log-formatnicejson / text / nice
SOCKET--socket/run/docker/plugins/docker-volume-loopback.sockName of the socket determines plugin name
DEFAULT_SIZE--default-size1GiB

When Docker's managed plugin system configuration can be adjusted via environment variables with the exception for SOCKET and MOUNT_DIR that have to be set to specific values. As for STATE_DIR and DATA_DIR they adjusted to /srv/run/docker-volume-loopback and /srv/var/lib/docker-volume-loopback respectively - host's file system can be accessed via /srv prefix.

Usage

Examples

Please note that examples below assume that the driver is run in manual mode and therefore is available as -d docker-volume-loopback. In managed mode (automatic installation) that will become -d ashald/docker-volume-loopback.

Create a regular volume using default filesystem (xfs) and size (1Gib):

$ docker volume create -d docker-volume-loopback foobar 

Create a sparse volume using custom filesystem (ext4) and size (100Mib):

$ docker volume create -d docker-volume-loopback foobar -o sparse=true -o fs=ext4 -o size=100MiB 

Create a regular volume using default filesystem (xfs) and size (1Gib) but adjust volume's root ownership and permissions:

$ docker volume create -d docker-volume-loopback foobar -o uid=1000 -o gid=2000 -o mode=777 
Options
OptionDefaultComment
sizeSet by DEFAULT_SIZE driver config optionSize in bytes or with a unit suffix K/M/T/P and Ki/Mi/Ti/Pi
sparsefalseWhether to reserve disk space or just set a limit: true or false
fsxfsFilesystem to format volume with: xfs or ext4
uid-1UID to set as owner of the volume's root, -1 means do not adjust
gid-1GID to set as owner of the volume's root, -1 means do not adjust
mode0Mode to set for volume's root, octal with up to 4 positions

Tag summary

Content type

Plugin

Digest

Size

9.7 MB

Last updated

over 7 years ago

docker plugin install ashald/docker-volume-loopback