AICollection Help

docker volume

The docker volume command is used to manage Docker volumes. Volumes are used to persist data generated by and used by Docker containers. This command provides various subcommands to create, inspect, list, and remove volumes.

Basic Syntax

docker volume [OPTIONS] COMMAND

Subcommands and Options

  1. create: Create a new volume.

    docker volume create [OPTIONS] VOLUME

    Options:

    • -d, --driver: Specify volume driver name (default is local).

      docker volume create -d local myvolume
    • -o, --opt: Set driver-specific options.

      docker volume create -o type=tmpfs -o device=tmpfs myvolume
  2. inspect: Display detailed information on one or more volumes.

    docker volume inspect VOLUME
  3. ls: List all volumes.

    docker volume ls
  4. rm: Remove one or more volumes.

    docker volume rm VOLUME
  5. prune: Remove all unused local volumes.

    docker volume prune

Examples

  1. Creating a Volume

    docker volume create myvolume

    This command creates a volume named myvolume with the default local driver.

  2. Creating a Volume with Specific Options

    docker volume create -o type=tmpfs -o device=tmpfs myvolume

    This command creates a volume named myvolume with the specified options.

  3. Listing All Volumes

    docker volume ls

    This command lists all the volumes available on the Docker host.

  4. Inspecting a Volume

    docker volume inspect myvolume

    This command displays detailed information about the volume named myvolume.

  5. Removing a Volume

    docker volume rm myvolume

    This command removes the volume named myvolume.

  6. Pruning Unused Volumes

    docker volume prune

    This command removes all unused local volumes.

Conclusion

The docker volume command is essential for managing Docker volumes. Understanding its subcommands and options allows you to effectively create, inspect, list, and remove volumes, as well as prune unused volumes.

Last modified: 05 December 2024