You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将本地文件复制到AWS ECS Fargate容器 实现类似Docker cp的功能

本地主机与AWS ECS Fargate容器互传文件的最优方案

目前最接近docker cp使用体验的方案是基于ECS Exec功能配合管道传输,无需依赖S3、EFS等中间存储,也不需要在容器内预安装AWS CLI,操作步骤更短。

前置依赖配置

  • Fargate任务使用的平台版本为1.4.0及以上
  • 任务定义中已开启enableExecuteCommand: true配置
  • 任务执行角色已添加SSM会话管理相关权限
  • 本地环境已安装AWS CLI v2及session-manager-plugin插件

具体操作命令

本地文件上传至Fargate容器

以下命令可将本地./test.txt文件直接传输到容器内的/data/目录下:

tar -cf - ./test.txt | aws ecs execute-command \
  --cluster 你的集群名称 \
  --task 目标Fargate任务ID \
  --container 目标容器名称 \
  --command "tar -xf - -C /data/" \
  --interactive

从Fargate容器下载文件到本地

以下命令可将容器内/data/log.txt文件下载到本地当前目录:

aws ecs execute-command \
  --cluster 你的集群名称 \
  --task 目标Fargate任务ID \
  --container 目标容器名称 \
  --command "tar -cf - /data/log.txt" \
  --interactive | tar -xf -

如果是小于1MB的纯文本小文件,也可以直接用base64转码传输,避免tar打包的额外开销:

# 上传示例
base64 ./small.txt | aws ecs execute-command \
  --cluster 你的集群名称 --task 目标任务ID --container 目标容器名 \
  --command "base64 -d > /data/small.txt" \
  --interactive

内容的提问来源于stack exchange,提问作者DivinoTaras

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 02:00:01