Docker Volumes Management

From WikiMLT
Revision as of 10:59, 24 May 2023 by Spas (talk | contribs) (Стадий: 3 [Фаза:Разработване, Статус:Разутвърден]; Категория:Containers)

Ba­sic com­mands

docker volume
Usage:  docker volume COMMAND

Manage volumes

Commands:
  create      Create a volume
  inspect     Display detailed information on one or more volumes
  ls          List volumes
  prune       Remove all unused local volumes
  rm          Remove one or more volumes

Run 'docker volume COMMAND --help' for more information on a command.
docker volume create volume_name
docker volume ls
docker volume inspect volume_name
sudo ls -la /var/lib/docker/volumes/
docker volume (rm|prune) volume_name

Ex­pla­na­tions

Note when you are us­ing dock­er com­pose, un­less spec­i­fy path in the left side on the ser­vices: con­tain­er-name: vol­umes: sec­tion dock­er will au­to­mat­i­cal­ly cre­ate a vol­ume /​​​var/​​​lib/​​​do­ck­er/​​​vo­lu­mes/​​​ named af­ter the con­tain­er-name un­der­score _ and the name of the vol­ume.

Ex­am­ples

example 1
docker-compose.yml
version: "3"
services:
  container-name:
    image: image_name
    volumes:
    - ./base:/data
The directory used as a volume is "./base" within the current directory where the "docker-compose.yml" is located.
example 2
docker-compose.yml
version: "3"
services:
  container-name:
    image: image_name
    volumes:
    - base:/data
volumes:
  base:
The directory used as a volume is "/var/lib/docker/volumes/container-name_base/" and it will be automatically created unless some additional options are specified within the "volumes:" section. The actual directory ":/data" of the container will be bound to "/var/lib/docker/volumes/container-name_base/_data"

Ref­er­ences