docker run program arguments in aws ecs

后端 未结 5 993
予麋鹿
予麋鹿 2021-02-07 04:59

I have a working container in Amazon\'s ECS that runs a program as a task. I would like to pass some program arguments, as I would do when running locally with docker run<

相关标签:
5条回答
  • 2021-02-07 05:12

    Use environment section in ecs task definition to inject your configs.

    "environment" : [
        { "name" : "string", "value" : "string" },
        { "name" : "string", "value" : "string" }
    ]
    

    Please refer to the following aws documentation http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_environment

    0 讨论(0)
  • 2021-02-07 05:13

    You can add command line arguments for the container entry point when creating new ECS task revision in AWS console. Open your container settings, and under the ENVIRONMENT label put the comma-separated list of command line arguments into the "Command" field.

    Example:

    --debug,--packages org.apache.hadoop:hadoop-aws:2.7.3
    

    will add 2 command line arguments to your container entry point.

    0 讨论(0)
  • 1. If you normally pass in command line arguments to your script like

    python myscript.py --debug --name "joe schmoe" --quality best --dimensions 1920 1080
    

    2. And you have a docker image with an entrypoint to run that script like

    FROM python:3.7-alpine
    
    # Add the application folder to the container
    COPY . /myscript
    WORKDIR /myscript
    
    # Install required packages
    RUN pip install -r requirements.txt --upgrade
    
    # Run the script when the container is invoked
    ENTRYPOINT ["python", "myscript.py"]
    

    3. Then when editing a task/container definition via the aws ecs user interface, you must place the arguments into the "Command" field under the "Environment" section of the container settings and replace all spaces between arguments and values with commas, like so:

    --debug,--name,joe schmoe,--quality,best,--dimensions,1920,1080
    

    Items with spaces like joe schmoe are quoted as "joe schmoe", which is why something like --quality best wouldn't work, and instead needs to be comma delimited as --quality,best

    4. After creating the task, if you take a look at the container details in the task definition, the command is displayed as:

    ["--debug","--name","joe schmoe","--quality","best","--dimensions","1920","1080"]
    

    which is the same syntax accepted by the CMD instruction in a Dockerfile.

    0 讨论(0)
  • 2021-02-07 05:27

    When you run a task in ECS you can specify container overrides.

    In the AWS console this can be found at the bottom in the Advanced Options section.

    On the CLI you can pass in a JSON object with the overrides like so:

    aws ecs run-task ... --overrides '{"containerOverrides": [{"name": "whatever", "command": ["foo", "bar"}]}'
    

    The command is the CMD that gets executed inside the container.

    In the same way environment variables can be passed to a container. Here's the list of possible options as described in the aws-cli docs:

    {
      "containerOverrides": [
        {
          "name": "string",
          "command": ["string", ...],
          "environment": [
            {
              "name": "string",
              "value": "string"
            }
            ...
          ],
          "cpu": integer,
          "memory": integer,
          "memoryReservation": integer
        }
        ...
      ],
      "taskRoleArn": "string",
      "executionRoleArn": "string"
    }
    

    For some reason the name always has to be set in the overrides. ¯\_(ツ)_/¯

    0 讨论(0)
  • 2021-02-07 05:32

    It was easy: the command line arguments can be passed as Command in ECS configuration, instead of entrypoint.

    0 讨论(0)
提交回复
热议问题