Skip to content

Instantly share code, notes, and snippets.

@wulab
Last active April 3, 2020 15:13
Show Gist options
  • Select an option

  • Save wulab/3dc8ae48355f08b83f508e85d95a92b3 to your computer and use it in GitHub Desktop.

Select an option

Save wulab/3dc8ae48355f08b83f508e85d95a92b3 to your computer and use it in GitHub Desktop.

Back up a Docker volume

To another volume

$ docker volume create --name <target>
$ docker run --rm -v <source>:/from -v <target>:/to alpine /bin/sh -c 'cp -av /from/* /to'

To an archive file

$ docker run --rm -v <source>:/from -v $(pwd):/to alpine /bin/sh -c 'tar -czvf /to/<source>.tar.gz . -C /from'

Restore from an archive file

$ docker volume create --name <target>
$ docker run --rm -v $(pwd):/from -v <target>:/to alpine /bin/sh -c 'tar -xzvf /from/<source>.tar.gz -C /to'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment