简体   繁体   English

在不再运行的容器中找到由 python 脚本编写的文件

[英]Locate files written by a python script in a container that is not running anymore

I have a python script that is dumping a pandas dataframe into a file using:我有一个 python 脚本,它使用以下命令将 pandas dataframe 转储到文件中:

dataframe.to_csv(file.csv)

After executing the docker container using:使用以下命令执行 docker 容器后:

Sudo docker-compose up freqtrade...(and the rest of the command) Sudo docker-compose up freqtrade...(以及命令的 rest)

I can't locate the file.csv and my cwd is freqtrade/ but can't access the filesystem in the container.我找不到文件。csv 并且我的 cwd 是 freqtrade/ 但无法访问容器中的文件系统。

Also tried to save the file to a path in the ubuntu file system but got the following error:还尝试将文件保存到 ubuntu 文件系统中的路径,但出现以下错误:

FileNotFoundError: [Errno 2] No such file or directory: '/home/kato/freqtrade/' FileNotFoundError:[Errno 2] 没有这样的文件或目录:'/home/kato/freqtrade/'

If the container has been stopped and has not been removed you should still find it using docker ps with -a :如果容器已停止且尚未删除,您仍应使用docker ps-a找到它:

docker ps -a

If you found the container ID, you can then copy files from its filesystem without starting it using docker cp :如果找到容器 ID,则可以从其文件系统复制文件,而无需使用docker cp启动它:

docker cp CONTAINER_ID:absolute/path/to/file ./host/target/path

Another solution to avoid doing this in the future, you could run your container with a bind mount (a directory from your machine would be mapped to a directory inside the container):另一种避免将来这样做的解决方案是,您可以使用绑定挂载运行容器(您机器中的目录将映射到容器内的目录):

docker run -v "$(pwd)"/relative/host_dir:/absolute/container_dir my_image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM