Docker Volumes Management: Difference between revisions

From WikiMLT
m (Стадий: 3 [Фаза:Разработване, Статус:Разработван]; Категория:Containers)
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude><!--[[Category:Hardware|?]]-->{{ContentArticleHeader/Containers}}</noinclude>
{{ContentArticleHeader/Containers|toc=off}}{{ContentArticleHeader/DevOps_and_SRE|toc-limit=2}}
 
== Basic commands ==
<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>
 
== 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&shy;ck&shy;er/vo&shy;lu&shy;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 ==
'''In Example 1''' the containers directory <code>:/data</code> will be bound (mounted) to the directory <code>./base</code> within the current directory where the <code>docker-compose.yml</code> is located. In this case no volume is specified.<syntaxhighlight lang="antlr-python" class="code-continue mlw-shell-gray">
example 1
</syntaxhighlight><syntaxhighlight lang="shell" class="code-continue">
container-name/docker-compose.yml
</syntaxhighlight>
 
<syntaxhighlight lang="yaml" line="1" highlight="6" class="code-continue mlw-shell-gray">
version: "3"
services:
  container-name:
    image: image_name
    volumes:
    - ./base:/data
 
</syntaxhighlight>
'''In Example 2''' the directory used as a volume is <code>/var/lib/docker/volumes/container-name_base/</code> and it will be automatically created unless some additional options are specified within the <code>volumes:</code> section. The actual directory <code>:/data</code> of the container will be bound to <code>/var/lib/docker/volumes/container-name_base/_data</code>
<syntaxhighlight lang="antlr-python" class="code-continue mlw-shell-gray">
example 2
</syntaxhighlight>
<syntaxhighlight lang="shell" class="code-continue">
container-name/docker-compose.yml
</syntaxhighlight>
<syntaxhighlight lang="yaml" line="1" highlight="6,8" class="code-continue mlw-shell-gray">
version: "3"
services:
  container-name:
    image: image_name
    volumes:
    - base:/data
volumes:
  base:
 
</syntaxhighlight>
 
== References ==
== References ==


* ...
* Docker:  [https://docs.docker.com/storage/volumes/ '''Manuals''' > Docker Engine > Storage > '''Volumes''']
 
* ...


== Section 1 ==
* 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 78:
{{devStage  
{{devStage  
  | Прндл  = Containers
  | Прндл  = Containers
  | Стадий = 3
| Прндл1 = DevOps_and_SRE
  | Фаза  = Разработване
  | Стадий = 6
  | Статус = Разработван
  | Фаза  = Утвърждаване
  | Статус = Утвърден
  | ИдтПт  = Spas
  | ИдтПт  = Spas
  | РзбПт  = {{REVISIONUSER}}
  | РзбПт = Spas
| АвтПт  = Spas
| УтвПт = {{REVISIONUSER}}
  | ИдтДт  = 24.05.2023
  | ИдтДт  = 24.05.2023
  | РзбДт  = {{Today}}
  | РзбДт = 24.05.2023
| АвтДт  = 24.05.2023
| УтвДт = {{Today}}
  | ИдтРв  = [[Special:Permalink/32547|32547]]
  | ИдтРв  = [[Special:Permalink/32547|32547]]
  | РзбРв  = {{REVISIONID}}
  | РзбРв = [[Special:Permalink/32566|32566]]
| АвтРв  = [[Special:Permalink/32567|32567]]
| РзАРв  = [[Special:Permalink/32558|32558]]
| УтвРв = {{REVISIONID}}
| РзУРв  = [[Special:Permalink/32563|32563]]
}}
}}
</div>
</div>
</noinclude>
</noinclude>

Latest revision as of 16:44, 24 May 2023

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 1) di­rec­to­ry-name where the docker-compose.yml is lo­cat­ed, 2) un­der­score _ and 3) the name of the vol­ume-name.

Ex­am­ples

In Ex­am­ple 1 the con­tain­ers di­rec­to­ry :/​​​data will be bound (mount­ed) to the di­rec­to­ry ./​​​base with­in the cur­rent di­rec­to­ry where the docker-compose.yml is lo­cat­ed. In this case no vol­ume is spec­i­fied.

example 1
container-name/docker-compose.yml
version: "3"
services:
  container-name:
    image: image_name
    volumes:
    - ./base:/data

In Ex­am­ple 2 the di­rec­to­ry used as a vol­ume is /var/lib/­dock­er/vol­umes/­con­tain­er-name_base/ and it will be au­to­mat­i­cal­ly cre­at­ed un­less some ad­di­tion­al op­tions are spec­i­fied with­in the vol­umes: sec­tion. The ac­tu­al di­rec­to­ry :/​​​data of the con­tain­er will be bound to /var/lib/­dock­er/vol­umes/­con­tain­er-name_base/_­da­ta

example 2
container-name/docker-compose.yml
version: "3"
services:
  container-name:
    image: image_name
    volumes:
    - base:/data
volumes:
  base:

Ref­er­ences