If we want to remove a particular service from the swarm, we can use the docker service rm command. If on the other hand we want to remove a stack from the swarm, we analogously use the docker stack rm command. This command removes all services that are part of the stack definition. In the case of the whoami service, it was created by using a stack file and thus we're going to use the latter command:
The preceding command will make sure that all tasks of each service of the stack are terminated, and the corresponding containers are stopped by first sending a SIGTERM, and then, if not successful, a SIGKILL after 10 seconds of timeout.
It is important to note that the stopped containers are not removed from the Docker host. Thus, it is advised to purge containers from time to time on worker nodes to reclaim unused resources. Use docker container purge -f for this purpose.