Moving file from docker to local while inside docker container

  containers, docker, docker-container, python

I’m having a python program that stores the output file in local. Now my code is run inside docker container I want to move the generated output file (like output.txt) to my local (outside the docker container)

I know there is a command which transfers files from docker to local:

docker cp <containerId>:/file/path/within/container /host/path/target

#I tried like this inside docker container but it didn't work
os.system(sudo docker cp <containerId>:/file/path/within/container /host/path/target) 

But since my program is executing inside docker this doesn’t work and I want to push the file to local as the code runs.

If you have any ideas please share them.

Source: Docker Questions

LEAVE A COMMENT