Skip to content

PROPOSAL: docker volumes list command #8363

@cpuguy83

Description

@cpuguy83

Problem

Volumes remain a hidden piece within Docker.

  1. Weather you are using normal volumes or host-mounted volumes, there is no way to get information about these volumes except by inspecting a container to find where these volumes are and manually inspecting them.
  2. There tend to be orphaned volumes because the only way to remove a volume correctly is by doing docker rm -v <container>, but most people do not think to do this.
  3. The most basic usage of a volume is to store state beyond the container's own lifecycle, however if you remove a container, it is mostly impossible to use that volume again. Because of this, we've invented the concept of a "data-only" container so it can hold a reference to that volume for you and you can just reference the container instead. This is pretty heavy on the management side and creates container clutter, for every volume there is a corresponding container that does nothing but hold a volume reference.

Proposal

New command: docker volumes ls, which produces output as such:

NAME                   CREATED                USED COUNT
jolly_torvalds         42 seconds ago         2
romatic_wozniak        About a minute ago     1

Optionally include the volumes size with docker volumes ls --size

Volumes would be automatically assigned a name when created through "docker run -v"
Through a separate command a volume could be created outside of the docker run and a name could be specified by the user or generated if none was specified (just as with containers).

New command: docker volumes inspect <voume>, which produces output as such:

{
        "ID": "124670d406cb783e37ad10d339e7f980db75460bcf4fedf1baa00566ebbcad63",
        "Name": "jolly_torvalds",
        "Created": "2014-10-01T16:17:01.417634973Z",
        "Path": "/var/lib/docker/vfs/dir/124670d406cb783e37ad10d339e7f980db75460bcf4fedf1baa00566ebbcad63",
        "IsBindMount": false,
        "Writable": true,
        "Containers": [
             "04b22da1ac4c47f758a3553d5c1c36e7510d1e99c80da19504f5f9112bc5491e",
             "835f0b9b62d09145d14339ee2f651df5d8dec1239c3c94b2cdc8a614649ecc1e"
         ],
        "Aliases": [
             "determined_brown:/foo",
             "angry_bell:/bar"
        ],
        "Size": "38325000"
}

Aliases are defined as the container_name:/mount/path for the container using a given volume.

Using an existing volume

Volumes can be referenced by docker run as such: docker run -v jolly_torvalds:/foo

Volumes can also be referenced using --volumes-from such as: docker run --volumes-from determined_brown:/foo, which is a volume alias.

Naming addendum

Volume's names will use the same random name generator as containers, but in a separate namespace. This means that a volume and a container, which may be completely unrelated to each other, could have the exact same name.
This also means a volume's alias (which would be a consuming container's name + the mount path in the container) may include a name that is also attached to a volume.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/volumesVolumeskind/featureFunctionality or other elements that the project doesn't currently have. Features are new and shiny

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions