Downloading/uploading 一个 file/folder 直接 from/to 一个 docker 容器 运行 在网络主机上 to/from 使用 SCP 的本地机器

Downloading/uploading a file/folder directly from/to a docker container running on a web host to/from a local machine using SCP

到目前为止,我总是先将文件从 docker 容器复制到我的虚拟机(Web 主机),然后从我的本地计算机使用 运行 scp 命令行从虚拟机。上传 files/folders 时发生了类似的情况。有使用 scp 的直接方法吗?

为了直接从您的容器中复制,您需要在容器上安装 sshd 并在 运行 容器时向 public 公开一个用于 ssh 的端口。 考虑到如果你这样做,你必须确保正确配置和保护 ssh。

Example: *We take in count that you already have ssh configured on the container

docker run -d -p 8000:22 --name docker image
scp -P 8000 username@myserver.com:/root/file.txt ~/file.txt