有没有办法将文件内容从其他容器复制到主机文件系统?

时间:2019-07-09 21:10:59

标签: python shell docker docker-container docker-image

我正在尝试将文本文件从Docker容器复制到主机文件系统。我们可以使用docker cp命令执行此操作,但真正的问题是:可能存在相同图像的其他容器,因为我的虚拟机将在一段时间后重新启动。重新启动计算机时,同一图像将有不同的容器ID。 我必须在python脚本中包含此命令,因此无法显式更改容器ID。

我尝试了 docker cp 命令,在其中必须提及容器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. 
    """

0 个答案:

没有答案