I have to import data files from a user local file C:/users/saad/bdd to a docker container (cassandra), I didn't find how to proceed using docker commands. I'm working on windows 7.
9 Answers
Use docker cp
.
docker cp c:\path\to\local\file container_name:/path/to/target/dir/
If you don't know what's the name of the container, you can find it using:
docker ps --format "{{.Names}}"

- 1,306
- 1
- 7
- 6
-
1Thank you Alvaro for your quick answer, but when I try this code: docker cp C:\Users\Saad\bdd-restaurants cassandra:/var/lib/docker/containers, I get this error message: copying between containers is not supported – Manou Oct 28 '16 at 22:49
-
2
-
2Please don't post duplicate answers, there are already quite a few good answers in the linked question. – Roman Oct 28 '16 at 23:31
-
1Ok, yes but everytime I try copying the files, it shows the same message "copying containers is not supported" do you know what does it mean please ? – Manou Oct 28 '16 at 23:45
-
-
@Manou I don't think your container has a /var/lib/docker/containers path. Your parent host (where you installed docker) surely does, but not the containers itself. I guess that's why it's giving you that error message. – Alvaro Carvajal Oct 30 '16 at 01:51
-
3One thing to note is that if you are using Docker for windows on Windows 7, and your container is a windows machine, then you will need to first stop the container in order to copy the file. Copying of files is not supported for running windows containers if they are Hyper V containers. The same command will however work fine if ran on Windows Server docker host. https://github.com/moby/moby/issues/31606 – Mandeep Singh May 15 '17 at 10:15
When using docker toolbox, there seems to be another issue related to absolute paths.
I am communicating with the containers using the "Docker Quickstart Teminal" which essentially is a MINGW64 environment.
If I try to copy a file with an absolute path to a container, I receive the error message.
$ docker cp /d/Temp/my-super-file.txt container-name:/tmp/
copying between containers is not supported
If I use a relative path, it simply works.
$ cd /d/
$ docker cp Temp/my-super-file.txt container-name:/tmp/
P.S.: I am posting this as an answer because of missing reputation for a comment.

- 194
- 1
- 3
Simple way:
From DockerContainer To LocalMachine
$docker cp containerId:/sourceFilePath/someFile.txt C:/localMachineDestinationFolder
From LocalMachine To DockerContainer
$docker cp C:/localMachineSourceFolder/someFile.txt containerId:/containerDestinationFolder

- 4,681
- 3
- 17
- 30
It is not as straight-forward when using docker toolbox. Because docker toolbox has only access to C:\Users\
folder and there is a Oracle Virtual Box Manager in between, when you do get to copy the folder it is not directly copied to the container but instead to a mounted volume handle by Oracle VM machine. Like so:
/mnt/sda1/var/lib/docker/volumes/19b65e5d9f607607441818d3923e5133c9a96cc91206be1239059400fa317611/_data
How I got around this is just editing my DockerFile:
FROM cassandra:latest
ADD cassandra.yml /etc/cassandra/
ADD import.csv /var/lib/cassandra/
EXPOSE 9042
And building it.

- 8,857
- 3
- 60
- 68
If you are using docker-toolbox on windows, use the following syntax
docker cp /C/Users/Saad/bdd-restaurants cassandra:/var/lib/docker/containers

- 47
- 1
-
1Your answer seems identical to [Alvaro Carvajal's one](http://stackoverflow.com/a/40313917/3982001). Can you please [edit] it and explain why it is different? Otherwise, if it isn't different, please consider that additional answers should add something to what has already been said, otherwise they aren't useful. Thank you! – Fabio says Reinstate Monica Apr 05 '17 at 17:33
-
This helped me realize that when using WSL2 and DevContainers with VS Code, in WSL your drives show up as /mnt/
. – ADataGMan Apr 21 '22 at 10:29
Use this command will help to copy files from host machine to docker container.
docker cp c:\abc.doc <containerid> :C:\inetpub\wwwroot\abc.doc

- 615
- 1
- 7
- 21
-
3It seems there should not be a space between
and the :C:\inetpub\... – Jared Thirsk Nov 08 '19 at 02:26
if you are trying to copy file from windows to an EC2 instance use the following in cmd (Putty enabled):
pscp -i "D:\path_to_ppk_key" c:\file_name ubuntu@**.***.**.*:/home/ubuntu/file
Then you can copy to docker in EC2 using
docker cp /home/ubuntu/file_name Docker_name:/home/

- 186
- 12
For those who are using WSL (Windows Subsystem for Linux), Docker, and DevContainers from VSCode (Visual Studio Code), I was able to make this work by using the WSL command line.
docker cp "/mnt/<drive letter>/source/My First Copy Command" <container id>:/workspace/destination/path
I also wrote it up in more detail.

- 449
- 1
- 7
- 23
You can also use volume to mount the file to container on the run:
docker run -v /users/saad/bdd:/myfiles/tmp/