Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orphaned Tasks in Docker Swarm after removal of failed node

Last week I had to remove a failed node from my Docker Swarm Cluster, leaving some tasks that ran on that node in desired state "Remove".

Even after deleting the stack and recreating it with the same name, docker stack ps stackname still shows them.

Interestingly enough, after recreating the stack, the tasks are still there, but with no node assigned. screenshot of docker stack ps

Here's what I tried so far to "cleanup" the stack:

  • Recreating the stack with the same name
  • docker container prune
  • docker volume prune
  • docker system prune

Is there a way to remove a specific task?

Here's the output for docker inspect fkgz0oihexzs, the first task in the list:

[
  {
    "ID": "fkgz0oihexzsjqwv4ju0szorh",
    "Version": {
      "Index": 14422171
    },
    "CreatedAt": "2018-11-05T16:15:31.528933998Z",
    "UpdatedAt": "2018-11-05T16:27:07.422368364Z",
    "Labels": {},
    "Spec": {
      "ContainerSpec": {
        "Image": "redacted",
        "Labels": {
          "com.docker.stack.namespace": "redacted"
        },
        "Env": [
          "redacted"
        ],
        "Privileges": {
          "CredentialSpec": null,
          "SELinuxContext": null
        },
        "Isolation": "default"
      },
      "Resources": {},
      "Placement": {
        "Platforms": [
          {
            "Architecture": "amd64",
            "OS": "linux"
          }
        ]
      },
      "Networks": [
        {
          "Target": "3i998stqemnevzgiqw3ndik4f",
          "Aliases": [
            "redacted"
          ]
        }
      ],
      "ForceUpdate": 0
    },
    "ServiceID": "g3vk9tgfibmcigmf67ik7uhj6",
    "Slot": 1,
    "Status": {
      "Timestamp": "2018-11-05T16:15:31.528892467Z",
      "State": "new",
      "Message": "created",
      "PortStatus": {}
    },
    "DesiredState": "remove"
  }
]

like image 887
zeisi Avatar asked Nov 06 '18 10:11

zeisi


People also ask

When a task stops it is not executed again and a new task may take its place?

When a task stops, it isn't executed again, but a new task may take its place. Tasks advance through a number of states until they complete or fail. Tasks are initialized in the NEW state. The task progresses forward through a number of states, and its state doesn't go backward.

What happens if docker swarm manager goes down?

Even if a swarm loses the quorum of managers, swarm tasks on existing worker nodes continue to run. However, swarm nodes cannot be added, updated, or removed, and new or existing tasks cannot be started, stopped, moved, or updated.

Does docker swarm restart container?

Updating the existing service, swarm will recreate all containers. For example, you can simply update a property of the service to archive restarting.


1 Answers

I had the same problem. I resolved it following this instructions :

docker run --rm -v /var/run/docker/swarm/control.sock:/var/run/swarmd.sock dperny/tasknuke <taskid>

Be sure to use the full long task id or it will not work (fkgz0oihexzsjqwv4ju0szorh in your case).

like image 131
SmartTom Avatar answered Sep 22 '22 16:09

SmartTom