且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何查看在Docker容器中创建的文件?

更新时间:2022-03-31 07:24:10

我看到至少两种简单的方法可以实现所需的目标:

I see at least two simple ways of achieving what you want:


  1. 使用绑定挂载。简而言之,您将使主机文件系统中的目录可用于容器,并使用其路径保存文件。输出将在该文件夹中提供。

  1. Use a bind mount. In short, you'll make a directory in your host filesystem available to the container, and you'll use its path to save the file. The output will be available in that folder.

使用 docker cp ,在容器退出后将文件从容器内的位置复制到主机文件系统中。

Use docker cp after the container exits to copy the file from a location inside the container into your host filesystem.

另一种不会使文件直接在您的主机文件系统上可用的方法是 docker exec -it<容器> bash ,这将在容器内为您提供一个开放的终端,您可以使用它将 cd 放入正确的目录中,并 cat 文件。

Another way, which will not make the file available directly on your host filesystem, will be to docker exec -it <container> bash, which will leave you with an open terminal inside the container, which you can use to cd into the correct directory and cat the file.