Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving files into a Docker Data Volume

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?

like image 468
Ole Avatar asked Mar 22 '17 18:03

Ole


People also ask

How do I import a file into a Docker container?

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.

Can a Docker volume be a file?

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.


1 Answers

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
like image 100
BMitch Avatar answered Oct 05 '22 02:10

BMitch