0

In Docker Swarm each container has both a task ID and a container ID. Given that orchestrators are aware of the containers they run and their Container IDs, why do they assign them a Task ID as well?

Both of these identifiers are unique for the same container so there is a 1 to 1 correlation between them. As can be seen here you can get the Container ID from the Task ID in Swarm via:

docker inspect -f "{{.Status.ContainerStatus.ContainerID}}" <task_id>

And as seen here you can get the opposite via:

docker inspect --format '{{ index .Config.Labels "com.docker.swarm.task.id"}}' <container_id>

I understand that for a container that is connected to an orchestrator there will be more relevant data related to it, however, it would seem to me that that data could be presented by the orchestrator according to the Container ID and there is no need for another identifier. So what is the point that the Task ID serves? What can you accomplish with it that could not be achieved otherwise?

In AWS ECS there is a similar thing however in ECS, you can have more than one container per task definition and those containers will share a task ID, so the correlation is not necessarily 1 to 1.

Uberhumus
  • 213
  • 1
  • 11

1 Answers1

0

This answer is based on an answer Bret Fisher, and a conversation with a friend. I can take very partial credit.

Basically the TaskID is a Swarm object and the ContainerID is a dockerd engine object. The swarm needs to have some sort of object ID before the container is even up so it created the TaskID. It can be seen in the docker documentation, the first three stages in the Task page are before the assignment of a container ID, because the Swarm doesn't even know what node it is going to be run on yet.

A cute experiment to see this in action follows:

The 3rd stage has to be run last, the 1st two are interchangeable.

  • In a 1 node swarm open three terminal windows.
  • In the 1st run watch docker service ps testTask
  • In the 2nd run watch docker ps
  • And in the 3rd and last run docker service create -e MYSQL_ROOT_PASSWORD=my-secret-pw --name testTask mariadb*

You will see the TaskID a few seconds before the ContainerID.

*This most likely can be achieved with other images as well but I would try a relatively large one.

Uberhumus
  • 213
  • 1
  • 11