- Newest
- Most votes
- Most comments
You can set Docker labels in your ECS task definition when using the AWS CLI by including them in the container definitions section of your task definition JSON. Docker labels are specified using the dockerLabels parameter, which is a key-value map of labels to add to the container.
Here's how to structure your register-task-definition command with Docker labels:
aws ecs register-task-definition \
--family "your-task-family" \
--container-definitions "[{
\"name\": \"your-container-name\",
\"image\": \"your-image\",
\"cpu\": 10,
\"memory\": 10,
\"essential\": true,
\"dockerLabels\": {
\"label1\": \"value1\",
\"label2\": \"value2\"
}
}]"
For a more complex task definition, you might want to store your JSON in a file and reference it:
aws ecs register-task-definition --cli-input-json file://task-definition.json
Where your task-definition.json file would include the dockerLabels parameter in the container definitions:
{ "family": "your-task-family", "containerDefinitions": [ { "name": "your-container-name", "image": "your-image", "cpu": 10, "memory": 10, "essential": true, "dockerLabels": { "label1": "value1", "label2": "value2" } } ] }
Note that Docker labels are added at the container definition level, not at the task level, and they cannot be overridden or set dynamically when running a task with the run-task command. They must be defined in the task definition itself.
Sources
Amazon ECS examples using AWS CLI - AWS SDK Code Examples
Amazon ECS task definition parameters for the Fargate launch type - Amazon Elastic Container Service
Amazon ECS task definition parameters for the EC2 launch type - Amazon Elastic Container Service
how to override / set Docker Labels by using the AWS-cli ecs run-task | AWS re:Post
Relevant content
asked 4 years ago
- AWS OFFICIALUpdated a year ago
