Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker run program arguments in aws ecs

Tags:

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. I have managed to do passing a new entrypoint in the container configuration in ECS, as if I were passing it in the docker run command line.

Unfortunately, when doing so, I am overriding the internal entrypoint that was already defined in the image. I would like to use the internal entrypoint, just adding some more command line arguments, like --debug options. Is there any way to do that?

Thanks in advance.

like image 262
cserpell Avatar asked Mar 10 '16 18:03

cserpell


People also ask

Does AWS ECS support Docker?

Development. Amazon ECS supports Docker and enables you to run and manage Docker containers. It even integrates into the Docker Compose CLI, so you can define and run multi-container applications.

How do I change environment variables in ECS?

To do it we should create a new revision of task definition with updated env variables and then tell the service to use new task definition. So, to create a new revision of task definition we should go to list of all revisions, select the last one and create a new revision.

Can ECS run Docker compose?

It is now even easier for a developer to take a containerized microservices-based application from their workstation and deploy it straight to the AWS Cloud. Developers can now run docker compose up and deploy their existing Docker Compose files straight to Amazon ECS, as previously shown here.

What are the mandatory parameters in the task definition in ECS?

Task definitions are split into separate parts: the task family, the IAM task role, the network mode, container definitions, volumes, task placement constraints, and launch types. The family and container definitions are required in a task definition.

What is the docker compose CLI for AWS ECS?

The Docker Compose CLI enables developers to use native Docker commands to run applications in Amazon Elastic Container Service (ECS) when building cloud-native applications. The integration between Docker and Amazon ECS allows developers to use the Docker Compose CLI to:

What is ECS rolling update in Docker Compose?

By default, the ECS rolling update is set to run twice the number of containers for a service (200%), and has the ability to shut down 100% containers during the update. The Docker Compose CLI configures AWS CloudWatch Logs service for your containers.

How do I connect to AWS from Docker?

Run the docker context create ecs myecscontext command to create an Amazon ECS Docker context named myecscontext. If you have already installed and configured the AWS CLI, the setup command lets you select an existing AWS profile to connect to Amazon. Otherwise, you can create a new profile by passing an AWS access key ID and a secret access key .

What is AWS ECS (elastic container service)?

This article is part 1 of a 4 part guide to running Docker containers on AWS ECS. ECS stands for Elastic Container Service. It is a managed container service that can run docker containers. Although AWS also offers container management with Kubernetes, (EKS) it also has its proprietary solution (ECS).


2 Answers

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

enter image description here

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.

enter image description here

like image 171
Roman Scher Avatar answered Dec 01 '22 09:12

Roman Scher


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.

enter image description here

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. ¯\_(ツ)_/¯

like image 31
udondan Avatar answered Dec 01 '22 09:12

udondan