docker / docker/cli

Implement import & export functionality for volumes

Open
#1,436 8 comments 59 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

I would like the ability to import and export volumes in Docker. I will explain each of these scenarios below. The motivation for this is that sometimes I like to be able to easily transition between bind mounts on the host and volumes managed by docker. If I previously started a container with a bind mount (which requires a directory on the host), I want to easily create a new volume with the contents of that directory, and run the container next time using a volume instead of a bind mount. The vice-versa of this scenario should also be supported. At the end of the day, the container doesn't know the difference and still sees the same data, this is just a management task for the host machine.

I also feel docker doing this is safer since it already has root privileges, and sudo won't be needed to copy in/out of /var/lib/docker which at the moment is locked down for even viewing.

Import Volumes

Use case: I have a directory that I want to recursively box into a docker volume. The end result of this operation should be:

docker volume create newvolume
cp -r /some/directory /var/lib/docker/volumes/newvolume/_data

Proposed docker command line usage for such a feature:

docker volume import /some/directory newvolume

This recursively copies the contents of /some/directory into a new volume named newvolume. Permissions should be retained during the copy (owners & permission bits). This is really just sugar coating over mkdir and cp, as shown in my earlier example.

Export Volumes

Use case: I have a volume that I want to convert to a directory, where that directory contains an exact recursive replica of the data in the volume. The end result of this operation should effectively be:

cp -r /var/lib/docker/volumes/existingvolume/_data/* /some/export/path

Example docker command line for such feature:

docker volume export existingvolume /some/export/path

pre & post conditions:

  • Destination directory must exist
  • The destination directory must be empty
  • The destination directory will receive the contents of the volume (recursively)
  • The destination directory contents will retain the permission bits & owner/group that was there in the volume itself

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed docker volume import and docker volume export command behaviors. Define how recursive copying, ownership, permission bits, existing destinations, and empty-directory requirements should be handled, then verify that both commands preserve the specified volume data semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.