I’m trying to copy the text file from a docker container to a host file system. We can do this using the docker cp command but the real issue is : There is a possibility that there might be a different container of the same image because my virtual machine will restart after sometime. And there will be a different container id for the same image when I restart my machine.
I have to include this commands in the python script and so I can not change the container ID explicitly.
I have tried the docker cp command in which we have to mention the container id.
def function(): write some data into the file. file.close() """ I need to execute commands or bash script here so that file I have created in the container can be copied to host file system given container id will change because of the machine restart. """