简体   繁体   English

将文件从 docker 容器内部发送到外部

[英]Send a file from inside the docker container to outside

docker cp is used to copy files from one container to host but you have to run docker cp from outside the container. docker cp用于将文件从一个容器复制到主机,但您必须从容器外部运行 docker cp。 My question is, how to do it when I am inside the container using command我的问题是,当我使用命令在容器内时如何做到这一点

docker exec -it container_id /bin/bash

Do we have something like scp here?我们这里有类似 scp 的东西吗?

I think the easiest way of doing this is to mount part of the host filesystem to the container and just spit out the file to the mount point.我认为最简单的方法是将主机文件系统的一部分挂载到容器中,然后将文件吐出到挂载点。

The whole idea of containers is that they're not able to do stuff with the host system unless the docker admin explicitly allows it.容器的整个想法是,除非 docker 管理员明确允许,否则它们无法对主机系统执行任何操作。

You may also try mounting the docker socket to the container (if it's a Docker-in-Docker container) and docker cp from within the container itself, but the first solution is way cleaner IMHO您也可以尝试将 docker 套接字安装到容器(如果它是 Docker-in-Docker 容器)和容器本身中的docker cp ,但第一个解决方案是更干净的恕我直言

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

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