4

This is how I am building a docker image, creating task definition, and deploying it to fargate cluster. My requirement is to mount a specific file from local to the container at the run time, not through the build. How can I achieve that?

task_definition = ecs.FargateTaskDefinition(
            self, f"td-{name}", task_role=task_execution_role,
            execution_role=task_execution_role,
            cpu=int(constants.task_instance_cpu)
        )

asset_docker_file = ecs.ContainerImage.from_asset(
            directory=directory,
            file=docker_file_name
        )
container = task_definition.add_container(
        id=f"cdk-deployer-{name}", container_name=name,
        image=asset_docker_file
    )
service = ecs.FargateService(
            self, f"cdk-deployer-service-{name}", cluster=cluster_name,
            service_name=name, assign_public_ip=True,
            task_definition=task_definition, security_groups=[security_group],
            desired_count=desired_count
        )
Dcook
  • 899
  • 7
  • 32
  • What do you mean by "from local"? – gshpychka Mar 01 '22 at 09:02
  • @gshpychka let's say I have custom yaml file in my machine from where I am running the cdk app, that file needs to be mounted. – Dcook Mar 01 '22 at 09:06
  • 1
    Okay, what do you mean by "at runtime", then? The file needs to be uploaded to AWS at build time. – gshpychka Mar 01 '22 at 09:09
  • @gshpychka Basically, files need to be available so that from the deployed app I can read that file contents. Currently I am changing the dockerfile, adding `COPY filename.yaml .` but I am not suppose to change the docker file, rather adding a volume or by using `bind mount` I want that file to be available. – Dcook Mar 01 '22 at 09:20
  • 1
    I'm curious - why not chang the dockerfile? This is by far the simplest solution. You can upload the file to S3 as part of the deployment and then transfer it to EFS with a custom resource and mount it to the container, but it's a couple orders of magnitude harder. – gshpychka Mar 08 '22 at 11:18

0 Answers0