Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created September 2, 2022 03:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mamemomonga/2bbb231bda8b2c701968e14257352338 to your computer and use it in GitHub Desktop.
DockerのNamed Volumeの基本的な使い方

DockerのNamed Volumeの基本的な使い方

作成

$ docker volume create hogehoge
hogehoge

一覧

$ docker volume ls
DRIVER    VOLUME NAME
local     hogehoge

ファイルを書いてみる

$ docker run --rm -v hogehoge:/data debian sh -c 'echo "Hello World!" > /data/hello.txt'

ファイルを読んでみる

$ docker run --rm -v hogehoge:/data debian cat /data/hello.txt

bashで入ってみる

$ docker run -it --rm -w /data -v hogehoge:/data debian bash
root@xxxxxxxxxxxx:/data# cat hello.txt
Hello World!
root@xxxxxxxxxxxx:/data# exit

バックアップ

$ docker run --rm -v hogehoge:/data busybox tar zcC /data . > data.tar.gz

削除

$ docker volume rm hogehoge

作成

$ docker volume create hogehoge

リストア

$ cat data.tar.gz | docker run -i --rm -v hogehoge:/data busybox tar zxvC /data

ファイルを読んでみる

$ docker run --rm -v hogehoge:/data debian cat /data/hello.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment