First we try to fetch the container. If it doesn't exist we return a 404 immediately. If it does exist, we try to delete it. If the container has been removed between these two calls, we will get a 500 status code and a different error message.
I would recommend removing the initial check so that the error is at least consistent as we do for volumes.
There is a race when deleting a container: https://github.com/docker/swarm/blob/master/api/handlers.go#L698-L706
First we try to fetch the container. If it doesn't exist we return a
404
immediately. If it does exist, we try to delete it. If the container has been removed between these two calls, we will get a500
status code and a different error message.I would recommend removing the initial check so that the error is at least consistent as we do for volumes.