0

I have logged into the docker from the below command, now from the python script i want to copy the file from docker to host system how to do this

      sudo  docker run -ti video:new /bin/bash

     import os
     os.system('cp /tmp/a.txt HOST:/tmp/a.txt') 

2 Answers 2

1

Map a volume to share data with your host from the container.

docker run -v /tmp/:/tmp/ -ti video:new /bin/bash

Then let your python script copy the file to the /tmp directory inside your container.

 import os
 os.system('cp /path/to/a.txt /tmp/a.txt') 

Through to the -v mapping, the file is placed on the docker host in the directory /tmp. Once you close your docker container, the file will still exist on the host as /tmp/a.txt.

Sign up to request clarification or add additional context in comments.

Comments

0

The container can't copy information outside its isolation. If you wanna share information between container and host, please use volume mapper to do that (-v):

https://docs.docker.com/userguide/dockervolumes/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.