Docker Volumes Management: Difference between revisions
m Стадий: 5 [Фаза:Утвърждаване, Статус:Авторизиран]; Категория:Containers |
|||
(One intermediate revision by the same user not shown) | |||
Line 31: | Line 31: | ||
== Explanations == | == Explanations == | ||
Note when you are using <code>docker compose</code>, unless specify path in the left side on the ''<code>services:</code> <code>container-name:</code> <code>volumes:</code>'' section docker will automatically create a volume <code>/var/lib/do­ck­er/vo­lu­mes/</code> named after the ''' | Note when you are using <code>docker compose</code>, unless specify path in the left side on the ''<code>services:</code> <code>container-name:</code> <code>volumes:</code>'' section docker will automatically create a volume <code>/var/lib/do­ck­er/vo­lu­mes/</code> named after the 1) '''directory-name''' where the <code>docker-compose.yml</code> is located, 2) underscore '''_''' and 3) the name of the '''volume-name'''. | ||
== Examples == | == Examples == | ||
Line 37: | Line 37: | ||
example 1 | example 1 | ||
</syntaxhighlight><syntaxhighlight lang="shell" class="code-continue"> | </syntaxhighlight><syntaxhighlight lang="shell" class="code-continue"> | ||
docker-compose.yml | container-name/docker-compose.yml | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 54: | Line 54: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="shell" class="code-continue"> | <syntaxhighlight lang="shell" class="code-continue"> | ||
docker-compose.yml | container-name/docker-compose.yml | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="yaml" line="1" highlight="6,8" class="code-continue mlw-shell-gray"> | <syntaxhighlight lang="yaml" line="1" highlight="6,8" class="code-continue mlw-shell-gray"> | ||
Line 79: | Line 79: | ||
| Прндл = Containers | | Прндл = Containers | ||
| Прндл1 = DevOps_and_SRE | | Прндл1 = DevOps_and_SRE | ||
| Стадий = | | Стадий = 6 | ||
| Фаза = Утвърждаване | | Фаза = Утвърждаване | ||
| Статус = | | Статус = Утвърден | ||
| ИдтПт = Spas | | ИдтПт = Spas | ||
| РзбПт = Spas | | РзбПт = Spas |
Latest revision as of 15:44, 24 May 2023
Basic commands
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
Explanations
Note when you are using docker compose
, unless specify path in the left side on the services:
container-name:
volumes:
section docker will automatically create a volume /var/lib/docker/volumes/
named after the 1) directory-name where the docker-compose.yml
is located, 2) underscore _ and 3) the name of the volume-name.
Examples
In Example 1 the containers directory :/data
will be bound (mounted) to the directory ./base
within the current directory where the docker-compose.yml
is located. In this case no volume is specified.
example 1
container-name/docker-compose.yml
version: "3"
services:
container-name:
image: image_name
volumes:
- ./base:/data
In Example 2 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
example 2
container-name/docker-compose.yml
version: "3"
services:
container-name:
image: image_name
volumes:
- base:/data
volumes:
base:
References
- Docker: Reference > Compose file reference > Compose specification > Volumes top-level element