Docker Volumes Management: Difference between revisions
From WikiMLT
m Стадий: 3 [Фаза:Разработване, Статус:Разработван]; Категория:Containers |
mNo edit summary |
||
Line 1: | Line 1: | ||
< | {{ContentArticleHeader/Containers|toc=off}}{{ContentArticleHeader/DevOps_and_SRE|toc-limit=2}} | ||
<syntaxhighlight lang="shell" line="1"> | |||
docker volume | |||
</syntaxhighlight><syntaxhighlight lang="shell-session"> | |||
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. | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray"> | |||
docker volume create volume_name | |||
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray"> | |||
docker volume ls | |||
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray"> | |||
docker volume inspect volume_name | |||
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray"> | |||
sudo ls -la /var/lib/docker/volumes/ | |||
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray"> | |||
docker volume (rm|prune) volume_name | |||
</syntaxhighlight>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 /var/lib/docker/volumes/ named after the '''container-name''' underscore '''_''' and the name of the '''volume'''.<syntaxhighlight lang="antlr-python" class="code-continue mlw-shell-gray"> | |||
example 1 | |||
</syntaxhighlight><syntaxhighlight lang="shell" class="code-continue"> | |||
docker-compose.yml | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="yaml" line="1" class="code-continue mlw-shell-gray"> | |||
version: "3" | |||
services: | |||
container-name: | |||
image: image_name | |||
volumes: | |||
- ./base:/data | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" class="mlw-pre-wrap"> | |||
The directory used as a volume is "./base" within the current directory where the "docker-compose.yml" is located. | |||
</syntaxhighlight><syntaxhighlight lang="antlr-python" class="code-continue mlw-shell-gray"> | |||
example 2 | |||
</syntaxhighlight><syntaxhighlight lang="shell" class="code-continue"> | |||
docker-compose.yml | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="yaml" line="1" class="code-continue mlw-shell-gray"> | |||
version: "3" | |||
services: | |||
container-name: | |||
image: image_name | |||
volumes: | |||
- base:/data | |||
volumes: | |||
base: | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" class="mlw-pre-wrap"> | |||
The directory used as a volume is "/var/lib/docker/volumes/container-name_base/_data" and it will be automatically created unles some additional options are specified within the "volumes:" section. | |||
</syntaxhighlight> | |||
== References == | == References == | ||
* .. | * Docker: [https://docs.docker.com/storage/volumes/ '''Manuals''' > Docker Engine > Storage > '''Volumes'''] | ||
* Docker: [https://docs.docker.com/compose/compose-file/07-volumes/ Reference > '''Compose file reference''' > Compose specification > Volumes top-level element] | |||
<noinclude> | <noinclude> | ||
Line 13: | Line 73: | ||
{{devStage | {{devStage | ||
| Прндл = Containers | | Прндл = Containers | ||
| Прндл1 = DevOps_and_SRE | |||
| Стадий = 3 | | Стадий = 3 | ||
| Фаза = Разработване | | Фаза = Разработване |
Revision as of 09:48, 24 May 2023
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
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 container-name underscore _ and the name of the volume.
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/_data" and it will be automatically created unles some additional options are specified within the "volumes:" section.
References
- Docker: Reference > Compose file reference > Compose specification > Volumes top-level element