因为rsync使用ssh传输文件,所以我认为这归结为能够远程ssh进入我的docker容器。
我目前有一个基本centos:6.6 docker容器,其端口转发从2222-> 22开始运行:
IMAGE COMMAND CREATED STATUS PORTS
a374fd62f97f "/bin/bash" 2 hours ago Up 2 hours 0.0.0.0:2222->22/tcp
我可以使用SSH进入运行docker服务的服务器
ssh -i key.pem ec2-user@PUBLIC_IP
从我的EC2实例中,在容器中安装openssh-server之后,可以使用以下命令将ssh放入容器中:
ssh root@127.0.0.1 -p 2222
但是,当我尝试使用ssh时:
ssh root@PUBLIC_IP -p 2222
它失败,并显示“拒绝连接”。 (我在EC2中的安全组在所有IP空间的入站上都打开了端口2222)
请您参考如下方法:
如果ssh可行,也许scp也会
scp root@${REMOTE_IP}:/tmp/remotefile /tmp/localfile
创建aws Elastic Block Store卷可能会更容易,您可以将其挂载到容器中,然后将数据复制到其中
...或S3存储桶...然后在本地复制
# ........ create s3 bucket
curr_bucketname=s3://${AWS_S3_BUCKET}
aws s3 mb ${curr_bucketname}
# ........ list buckets
aws s3 ls
然后将S3存储桶安装到您的容器中,然后填充
# ........ copy local dir to s3
aws s3 sync /opt/my/local/dir/of/files/ ${curr_bucketname}
# ... copy s3 bucket to populate (or just refresh) local dir
aws s3 sync ${curr_bucketname} /usr/tmp/local/dir




