简体   繁体   English

如何将文件复制到docker-cloud容器中? (又名:如何在不使用scp的情况下通过ssh复制文件)

[英]How do I copy a file into a docker-cloud container? (AKA How to copy a file over ssh without using scp)

docker-machine has an scp command, but docker-cloud doesn't seem to have any way to transfer a file from my local machine to the cloud container or vice-versa. docker-machine有一个scp命令,但是docker-cloud似乎没有任何方法可以将文件从本地计算机传输到云容器,反之亦然。

I'm submitting an answer below that I've finally figured out (in hopes that it will help someone), but I'd love to hear better answers if there are any! 我在下面提交一个我终于想出的答案(希望它对某人有帮助),但是如果有任何答案,我希望能听到更好的答案!

(I realize docker-cloud is going away, but perhaps this will be helpful for other cloud platforms as well) (我意识到docker-cloud即将消失,但这也许也会对其他云平台有所帮助)

To transfer a file from your local machine to a docker-cloud instance that is running linux with the tee command available: 使用tee命令将文件从本地计算机传输运行linux的docker-cloud实例:

docker-cloud container exec id12345 tee filename.ext < file_to_copy.ext > /dev/null

(you'll want to redirect output to /dev/null as shown unless you want the entire contents of the file to be echoed to the terminal... twice) (除非您希望将文件的全部内容回显到终端...两次,否则您将如图所示将输出重定向到/dev/null

To transfer a file to your local machine, is somewhat easier: 要将文件传输到本地计算机,会稍微容易一些:

docker-cloud container exec id12345 cat file_to_copy.ext > filename.ext

Note: I'm not sure this works for binary files, and it can even cause issues with linefeed characters in text files, based on terminal settings, etc. - but it's the best answer I've got short of using an external service like https://transfer.sh 注意:我不确定这是否适用于二进制文件,甚至可能会导致文本文件中的换行符出现问题(基于终端设置等)-但这是最好的答案,因为我缺少使用外部服务(例如https://transfer.sh

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

相关问题 如何使用 SCP 或 SSH 将文件复制到 Python 中的远程服务器? - How to copy a file to a remote server in Python using SCP or SSH? 如何使用phpseclib(SSH2)将文件复制到服务器 - How to copy file over to server using phpseclib (SSH2) 我如何使用最新的Ganymed SSH2 SCP加密将文件上传到服务器 - How do I SCP a file up to the server using the latest Ganymed SSH2 SCP Implmentation 在多个级别或 SSH 跃点上使用 rsync 或 scp 复制文件 - Copy file with rsync or scp over multiple level or hops of SSH 如何通过ssh在php中获取远程文件并将文件直接返回浏览器响应,而无需在网络服务器上创建文件的副本 - How can I fetch a remote file in php over ssh and return file directly to the browser response without creating a copy of the file on the webserver 无法在scp ssh中复制带有空格的文件名 - could not copy file name with space in scp ssh 如何将文件从本地机器直接 scp 到远程机器上的 docker 容器(无需重复复制)? - How to scp files from local machine directly to a docker container on a remote machine (without having to repeatedly copy)? java scp ssh文件复制到远程目录 - java scp ssh file copy to remote dir 使用 ssh 复制容器 Docker - copy container Docker using ssh 如何使用 scp 将文件夹从远程复制到本地? - How do I copy a folder from remote to local using scp?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM