获取Docker容器中的所有文件和文件夹的方法是使用以下命令:

huangapple go评论48阅读模式
英文:

How to get all file and folders of a docker container?

问题

我有一个正在运行的 Docker 容器的服务器。我可以通过运行 docker container ls 命令看到它:

获取Docker容器中的所有文件和文件夹的方法是使用以下命令:

然后,通过运行 docker image ls 命令查找镜像:

获取Docker容器中的所有文件和文件夹的方法是使用以下命令:

我还可以使用以下命令打开容器:docker exec -it <container_hash> sh。我只需要从项目的文件中制作一个 zip 文件。我指的是这些文件:

获取Docker容器中的所有文件和文件夹的方法是使用以下命令:

那么,我如何复制/粘贴正在运行的容器的所有文件,并在服务器上制作一个 zip 文件?请注意,我使用的是 Ubuntu 20.04。

英文:

I have a server that a docker container is running on. I can see it by running docker container ls:

获取Docker容器中的所有文件和文件夹的方法是使用以下命令:

And finding the image by running docker image ls:

获取Docker容器中的所有文件和文件夹的方法是使用以下命令:

I also can open the container using this command docker exec -it <container_hash> sh. All I need to do is making a zip file from the files of the project. I mean these files:

获取Docker容器中的所有文件和文件夹的方法是使用以下命令:

So, how can I copy/paste all files of a running container and make a zip file of them on the server? Noted that I use Ubuntu 20.04

答案1

得分: 1

docker cp 在这里非常有用:

用法:docker cp [选项] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [选项] SRC_PATH| CONTAINER:DEST_PATH

在容器和本地文件系统之间复制文件/文件夹

使用'-'作为源以从标准输入读取tar归档文件
并将其提取到容器中的目标目录中。
使用'-'作为目标以将容器源的tar归档文件流式传输到标准输出。

选项:
-a,--archive 归档模式(复制所有uid/gid信息)
-L,--follow-link 始终跟随SRC_PATH中的符号链接

所以在你的情况下,你可以使用:

docker cp <container_name>:/app /local/path/for/directory

这将把目录复制到你的本地文件系统。从那里,你可以使用实用程序以任何你想要的格式创建归档文件。

英文:

docker cp is your friend here:

Usage:  docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Copy files/folders between a container and the local filesystem

Use &#39;-&#39; as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use &#39;-&#39; as the destination to stream a tar archive of a
container source to stdout.

Options:
  -a, --archive       Archive mode (copy all uid/gid information)
  -L, --follow-link   Always follow symbol link in SRC_PATH

So in your case you could use

docker cp &lt;container_name&gt;:/app /local/path/for/directory

This will copy the directory out to your local file system. From there you can use a utility to create an archive in whatever format you want.

huangapple
  • 本文由 发表于 2023年2月10日 06:55:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定