0

I'm new to using labels with Docker containers, but I noticed that the labels I add to my images during build are ignored by ECS when I deploy a task definition.

I can see that I can add the labels to the container as part of the task definition, but is there any way to make ECS respect the labels embedded in the image? Specifically, I would like to be able to see them when I inspect a running task.

Currently the task just lists "Docker labels - not configured" under the container's properties in the console, and doesn't include them when I use the CLI to describe the task-definition, service, or the running container instance.

mhvelplund
  • 87
  • 12

1 Answers1

0

From the official documentation of ECS docker volumes:

{
    "containerDefinitions": [
        {
            "mountPoints": [
                {
                    "sourceVolume": "string",
                    "containerPath": "/path/to/mount_volume",
                    "readOnly": boolean
                }
            ]
        }
    ],
    "volumes": [
        {
            "name": "string",
            "dockerVolumeConfiguration": {
                "scope": "string",
                "autoprovision": boolean,
                "driver": "string",
                "driverOpts": {
                    "key": "value"
                },
                "labels": {
                    "key": "value"
                }
            }
        }
    ]
}

What happens if you run the example above on a ECS task of yours?

Does your task include the "labels" item at the correct level (i.e. in the "volumes" section)?

This should actually be the same as issuing:

docker volume create --label YourLabel 

Cheers :)

  • "in Docker, labels can only be assigned to volumes (not to containers)." ... that is at odds with Docker's documentation (https://docs.docker.com/config/labels-custom-metadata/). As far as I can tell, ECS also supports it via "dockerLabels" on container definitions (https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html). I don't think your answer is correct. – mhvelplund May 07 '19 at 17:37
  • Thanks, you are right: amended. did you try the task above? – RafDouglas C. Tommasi May 07 '19 at 20:49
  • Unfortunately I'm using a mix of EC2 and Fargate containers, som volumes are not an option for all my uses, and even if it worked, it feels like a hack to use that to store stuff like build ids and source branches :) – mhvelplund May 08 '19 at 11:09