如何列出已停止的Docker容器中的文件 [英] How to list files in a stopped Docker container

查看:165
本文介绍了如何列出已停止的Docker容器中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题显示了如何从文件中复制文件一个停止的容器.这要求我知道文件的完整路径,包括其文件名.我知道要从中复制文件的目录,但是我不知道其文件名,因为该文件名是动态生成的.如何在停止的Docker容器中的目录中 列出 文件?

This question shows how to copy files out of a stopped container. This requires that I know the full path to the file including its file name. I know the directory I want to copy a file out of, but I do not know its file name since that is generated dynamically. How do I list the files in a directory in a stopped Docker container?

如果Docker容器正在运行,则以下Docker命令非常有用.但是,如果Docker容器停止,则失败.

The following Docker command works great if the Docker container is running. But, it fails if the Docker container is stopped.

docker exec --privileged MyContainer ls -1 /var/log

注意:文件不会存储在永久卷中.

Note: The files are not stored in a persistent volume.

推荐答案

针对另一个问题的答案显示了如何开始使用另一个命令停止的容器.这是列出停止容器中文件的命令.

This answer to another question shows how to start a stopped container with another command. Here are the commands to list files in a stopped container.

  1. 将已停止的容器提交到新图像: test_image .
    • docker commit $ CONTAINER_ID test_image
  • docker run -ti --entrypoint = sh test_image
  • docker exec --privileged $ NEW_CONTAINER_ID ls -1/var/log

这篇关于如何列出已停止的Docker容器中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆