python - 有没有办法将文件内容从不同的容器复制到主机文件系统?
问题描述
我正在尝试将文本文件从 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.
"""
解决方案
推荐阅读
- node.js - 在 AMAZON EC2 上部署 MERN 堆栈应用程序的最佳方法是什么?
- kotlin - kotlin 暴露的 DSL 中的 SQL Select 查询
- javascript - 如何在 XMLHttpRequest 中获取 PromiseValue。JSON
- python - Python:Uexpected 一个缩进块
- r - Bnlearn 内存不足
- html - 如何正确地将标题背景颜色传播到边缘?
- cakephp - 直接使用分页器是无法识别配置的
- html - SCSS 动画复选框:动态宽度
- android - 毕加索从网址下载图片
- flutter - 颤振在 CupertinoPicker 小部件中使用循环传递字符串列表