First I create a volume:
docker volume create --name some-volume
Then I create a file touch ~/somefile.txt
Now I want to move ~/somefile.txt
into the root of the volume some-volume
. How do I do this?
First, set the path in your localhost to where the file is stored. Next set the path in your docker container to where you want to store the file inside your docker container. Then copy the file which you want to store in your docker container with the help of CP command.
Docker volumes are file systems mounted on Docker containers to preserve data generated by the running container. The volumes are stored on the host, independent of the container life cycle. This allows users to back up data and share file systems between containers easily.
You can do this with a container:
docker run --rm -v `pwd`:/source -v some-volume:/target \
busybox cp -av /source/somefile.txt /target/somefile.txt
I will also use tar and stdin to pipe files into a remote volume over the docker client/server connection:
tar -cv -C source-dir . | \
docker run --rm -i -v some-volume:/target busybox tar -xC /target
An export is similar:
docker run --rm -v some-volume:/source busybox tar -cC /source . | \
tar -xC target-dir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With