Search code examples
amazon-ecs

How to set the name of the container when ecs deploys the image


When ECS deploys the container, the name of the container comes as

ecs-xray-daemon-family2-1-xray-daemon2-f08780e2a097d7dac101

Is there an option where we can control the name of the container?

CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS                 PORTS                               NAMES

9957f08908fa        amazon/aws-xray-daemon   "/usr/bin/xray -t 0.…"   About an hour ago   Up About an hour       2000/tcp, 0.0.0.0:32768->2000/udp   ecs-xray-daemon-family2-1-xray-daemon2-f08780e2a097d7dac101

I have mentioned the name of the container in the task definition like this so I would expect the name of the container to be xray-daemon2 enter image description here


Solution

  • No, because the container names in ECS need to be unique to avoid conflicts. Thus there is a code that randomizes parts of the name. Something roughly like this:

    containerName := "ecs-" + task.Family + "-" + task.Version + "-" + name + "-" + utils.RandHex()
    

    (But you could use the labels in the task ARN to extract the container name that you provided)