How to copy files from a local computer to a docker container on windows

I need to import data files from the local user file C: / users / saad / bdd into the docker container (cassandra), I did not find how to continue using docker commands. I am working on windows 7.

Thank you very much for your help

+15
source share
7 answers

Use docker cp .

 docker cp c:\path\to\local\file container_name:/path/to/target/dir/ 

If you do not know what the name of the container is, you can find it using:

 docker ps --format "{{.Names}}" 
+33
source

If you use the docker toolbar for Windows, use the following syntax

docker cp / C / Users / Saad / bdd-restaurants cassandra: / var / lib / docker / containers

+2
source

This is not so straightforward when using the docker toolbar. Since the docker toolbar has access only to the C:\Users\ folder, and between them there is the Oracle Virtual Box Manager, when you copy the folder, it is not directly copied to the container, but instead to the installed volume descriptor using the Oracle VM machine. For instance:

 /mnt/sda1/var/lib/docker/volumes/19b65e5d9f607607441818d3923e5133c9a96cc91206be1239059400fa317611/_data 

How I got around this, just edited my DockerFile :

 FROM cassandra:latest ADD cassandra.yml /etc/cassandra/ ADD import.csv /var/lib/cassandra/ EXPOSE 9042 

And build it.

+2
source

When using the Docker toolbar, there seems to be another problem with absolute paths.

I communicate with containers using the Docker Quick Launch Docker, which is essentially a MINGW64 environment.

If I try to copy a file with an absolute path to the container, I get an error.

 $ docker cp /d/Temp/my-super-file.txt container-name:/tmp/ copying between containers is not supported 

If I use a relative path, it just works.

 $ cd /d/ $ docker cp Temp/my-super-file.txt container-name:/tmp/ 

PS: I am posting this as an answer due to lack of reputation for comment.

+2
source

Here just do it like an answer

  belzebub-system:~/Documents/dead-exorcist/satan_ml$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 94ef16fa1d18 tensorflow/tensorflow "/run_jupyter.sh --a…" 2 days ago Up 2 days 6006/tcp, 0.0.0.0:8888->8888/tcp adoring_engelbart belzebub-system:~/Documents/dead-exorcist/satan_ml$ docker ps --format "{{.Names}}" adoring_engelbart belzebub-system:~/Documents/dead-exorcist/satan_ml$ docker cp ~/Documents/dead-exorcist/satan_ml/satan_ml.tar.gz adoring_engelbart:/notebooks belzebub-system:~/Documents/dead-exorcist/satan_ml$ 
0
source

Using this command will help copy files from the host machine to the docker container.

 docker cp c:\abc.doc <containerid> :C:\inetpub\wwwroot\abc.doc 
0
source

if you are trying to copy a file from windows to an EC2 instance, use the following command in cmd (Putty is 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/ 
0
source

Source: https://habr.com/ru/post/1011830/


All Articles