在不再是 运行 的容器中找到由 python 脚本编写的文件
Locate files written by a python script in a container that is not running anymore
我有一个 python 脚本,它使用 :
将 pandas 数据帧转储到一个文件中
dataframe.to_csv(file.csv)
执行 docker 容器后使用:
sudo docker-compose up freqtrade # ...rest of the command
我找不到 file.csv 并且我的 cwd 是 freqtrade/ 但无法访问容器中的文件系统。
还尝试将文件保存到 ubuntu 文件系统中的路径,但出现以下错误:
FileNotFoundError: [Errno 2] No such file or directory: '/home/kato/freqtrade/'
如果容器已停止且未被删除,您仍然应该使用 docker ps 和 -a
:
找到它
docker ps -a
如果找到容器 ID,则可以从其文件系统复制文件而无需使用 docker cp:
启动它
docker cp CONTAINER_ID:absolute/path/to/file ./host/target/path
另一种避免将来这样做的解决方案,您可以 运行 您的容器带有 bind mount(您机器上的目录将映射到容器内的目录):
docker run -v "$(pwd)"/relative/host_dir:/absolute/container_dir my_image
我有一个 python 脚本,它使用 :
将 pandas 数据帧转储到一个文件中dataframe.to_csv(file.csv)
执行 docker 容器后使用:
sudo docker-compose up freqtrade # ...rest of the command
我找不到 file.csv 并且我的 cwd 是 freqtrade/ 但无法访问容器中的文件系统。
还尝试将文件保存到 ubuntu 文件系统中的路径,但出现以下错误:
FileNotFoundError: [Errno 2] No such file or directory: '/home/kato/freqtrade/'
如果容器已停止且未被删除,您仍然应该使用 docker ps 和 -a
:
docker ps -a
如果找到容器 ID,则可以从其文件系统复制文件而无需使用 docker cp:
启动它docker cp CONTAINER_ID:absolute/path/to/file ./host/target/path
另一种避免将来这样做的解决方案,您可以 运行 您的容器带有 bind mount(您机器上的目录将映射到容器内的目录):
docker run -v "$(pwd)"/relative/host_dir:/absolute/container_dir my_image