How to deregister service

I’ve service with id _nomad-task-53a3c80d-81ef-330d-6b3e-47b2ccfc5e21-cadvisor-exporter-cadvisor-exporter-metrics
I tried to deregister it with command
consul services deregister -id=‘_nomad-task-53a3c80d-81ef-330d-6b3e-47b2ccfc5e21-cadvisor-exporter-cadvisor-exporter-metrics’
but i’ve received this error
Error deregistering service “”: Unexpected response code: 404 (Unknown service ID “_nomad-task-53a3c80d-81ef-330d-6b3e-47b2ccfc5e21-cadvisor-exporter-cadvisor-exporter-metrics”. Ensure that the service ID is passed, not the service name.)

According to the help message of consul services deregister, it interacts with the local agent.

Therefore, the error received would be consistent with you running the command against some other agent in your cluster, besides the agent that is local for this service.

Run the command against the specific local agent managing the registration of this service, or (if the service is no longer registered with any local agent, and just persists in the cluster’s data) use the catalog deregister API against a Consul server. I don’t think there is a CLI command for that, so you’ll need to make the request with curl or similar.

Normally this would not be required, as there would usually be a health check of some kind, which would make the service critical, leading to it being automatically deregistered after remaining critical for a configured time limit.