如何在容器开始在AWS ECS fargate集群中运行之前使外部文件可用



我是docker的新手,我有一个docker文件,其中包含构建docker映像的所有指令。图像必须部署在AWS Fargate集群中。现在我有了一个python脚本,它可以做以下事情:

1. clone a repo from GitHub
2. Locate the docker file, build the image and push the docker image to AWS ecr
3. Create a task definition and deploy into ECS fargate cluster
4. Additionally the script generate a YAML file based on certain logic that has certain parameters(not related to container config) which is required for the application

在容器开始在AWS中运行之前,我如何使该文件内容可用于容器?我正在检查--entrypoint和--cmd,但在这里我无法更改Dockerfile

有什么方法可以在不更改Dockerfile的情况下实现这一点吗?

如果没有Dockerfile,就无法将层添加到docker映像中。但是,您可以在原始映像之上构建一个新的映像,COPY处理文件,并保留ENTRYPOINTCMD和其他配置。

  1. 构建";中间体";来自上游Dockerfile的图像,给它一个稍后可以参考的标签:

    docker build -t my-intermediate-image:my-version-tag .
    
  2. 创建您的yaml文件到myfile.yml

  3. 创建一个新的Dockerfile.final,启动FROM中间体:

    FROM my-intermediate-iamge:my-version-tag
    COPY myfile.yml /expected/yaml/path
    
  4. 使用ECS标签构建最终图像:

    docker build -f Dockerfile.final -t accountnumber.ecs.amazonaws.com:my-version .
    
  5. 将最终图像标签推送到ECS

  6. 继续更新ECS任务定义以指向新图像

最新更新