-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to copy files into a named volume without an attached container? #25245
Comments
That's the way to do it. For configuration files, you could consider using a bind-mount, or perhaps a volume driver that allows mounting configuration as a volume https://docs.docker.com/engine/extend/plugins/#/volume-plugins |
I'm closing this issue, because this is a question, not a bug report, but feel free to continue the discussion |
Thanks for the quick reply. Has there been a consensus decision not to support "copy into volume", or is this something that could be requested as a feature? If there has been a decision, what was the rationale? |
Oh, yes, there is an open feature request, but it hasn't been decided on yet; see #18718. |
Perfect, thank you. |
Do you want to copy a file to a docker volume, but the volume doesn't have a container? I'll tell you how I do it. Unfortunately, you do need a container. But, this is actually the lightest-weight method I have found so far. Basic Idea
Step by Step Example
You can also copy the other way (from the volume to the local file system).
If there's a better way, I'd love to know what it is! |
There's no need to start the container, just creating a container is enough;
|
Here's a one-liner that copies |
@thaJeztah That's cool, thanks! Now I'm wondering, is there an image that is lighter weight than hello-world? I can't just create a container running So, I used the following Dockerfile to create a nothing image.
Now my steps are:
|
@wyckster |
Here is my convenience script:
Explanation:
Examples:
|
@mvasin |
@janusznoszczynski, you should be able to use Assume you're running a container named docker cp foobar:/root/myfile.txt /root This will copy the More details listed here: https://docs.docker.com/engine/reference/commandline/cp/ |
From volume to host (into the current directory!): |
and what about remove copied files after all inner procedures inside docker volume? |
Combined #25245 (comment), #25245 (comment), and #25245 (comment) for a quick(dirty?) script for copying file/folder into a Volume. Usage is |
I improved a bit the script from @dorintt to avoid container name collisions, for example if executed concurrently.
|
Any news about the native support of this feature? All related issues seem to be closed |
If I create a volume with:
docker volume create --name test-volume
I would like to then copy
example.cfg
into the volume. However,docker cp
works with containers, not volumes.Right now, I need to create a container that mounts the volume, copy the file in, then remove the container. Alternatively, I can inspect the volume and modify the filesystem directly. Is there a better way?
The text was updated successfully, but these errors were encountered: