Skip to content Skip to sidebar Skip to footer

Copy File From Docker To Host System Using Python Script

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

Solution 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 osos.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.

Solution 2:

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/

Post a Comment for "Copy File From Docker To Host System Using Python Script"