Graceful shutdown, reboot, and clean-up

Estimated reading time: 4 minutes

The voting app will continue to run on the swarm while the manager and worker machines are running, unless you explicitly stop it. The following topics explain how to stop and start the app, remove the app but keep the swarm, or remove the machines entirely.

Stopping the voting app

To shut down the voting app, simply stop the machines on which it is running. If you are using local hosts, follow the steps below. If you are using cloud hosts, stop them per your cloud setup.

  1. Open a terminal window and run docker-machine ls to list the current machines.

    $ docker-machine ls
    NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
    manager   -        virtualbox   Running   tcp://192.168.99.100:2376           v1.13.1   
    worker    -        virtualbox   Running   tcp://192.168.99.101:2376           v1.13.1   
    
  2. Use docker-machine stop to shut down each machine, beginning with the worker.

    $ docker-machine stop worker
    Stopping "worker"...
    Machine "worker" was stopped.
    
    $ docker-machine stop manager
    Stopping "manager"...
    Machine "manager" was stopped.
    

Restarting the voting app

If you want to come back to your manager and worker machines later, you can keep them around. One advantage of this is that you can simply restart the machines to launch the sample voting app again.

To restart local machines, follow the steps below. To restart cloud instances, start them per your cloud setup.

  1. Open a terminal window and list the machines.

    $ docker-machine ls
    NAME      ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
    manager   -        virtualbox   Stopped                 Unknown   
    worker    -        virtualbox   Stopped                 Unknown   
    
  2. Run docker-machine start to start each machine, beginning with the manager.

    $ docker-machine start manager
    Starting "manager"...
    (manager) Check network to re-create if needed...
    (manager) Waiting for an IP...
    Machine "manager" was started.
    Waiting for SSH to be available...
    Detecting the provisioner...
    Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
    
    $ docker-machine start worker
    Starting "worker"...
    (worker) Check network to re-create if needed...
    (worker) Waiting for an IP...
    Machine "worker" was started.
    Waiting for SSH to be available...
    Detecting the provisioner...
    Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
    
  3. Run the following commands to log into the manager and see if the swarm is up.

    docker-machine ssh manager
    
    docker@manager:~$ docker stack services vote
    ID            NAME             MODE        REPLICAS  IMAGE
    74csdxb99tg9  vote_visualizer  replicated  1/1       dockersamples/visualizer:stable
    jm0g1vahcid9  vote_redis       replicated  2/2       redis:alpine
    mkk6lee494t4  vote_db          replicated  1/1       postgres:9.4
    o3sl1wr35yd6  vote_worker      replicated  1/1       dockersamples/examplevotingapp_worker:latest
    qcc8dw2zafc1  vote_vote        replicated  2/2       dockersamples/examplevotingapp_vote:after
    x5wcvknlnnh7  vote_result      replicated  1/1       dockersamples/examplevotingapp_result:after
    

At this point, the app is back up. The web pages you looked at in the test drive should be available, and you could experiment, modify the app, and redeploy.

Removing the voting app

To remove the application, but keep the swarm running, do the following:

  1. Log into the manager with docker-machine ssh manager.

  2. Run docker stack rm [APP-NAME], e.g., docker stack rm vote:

    docker@manager:~$ docker stack rm vote
    Removing service vote_db
    Removing service vote_redis
    Removing service vote_worker
    Removing service vote_vote
    Removing service vote_result
    Removing service vote_visualizer
    Removing network vote_backend
    Removing network vote_frontend
    Removing network vote_default
    docker@manager:~$ docker stack services vote
    Nothing found in stack: vote
    docker@manager:~$ docker node ls
    ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
    1q0nmgrvbfk9kwj3r9lo85l94 *  manager   Ready   Active        Leader
    a4zgsyk5upjfc4g6dv89seq69    worker    Ready   Active        
    

    This removes the voting application and all its services from both manager and worker nodes.

  3. Run docker stack services vote to verify that the application was removed.

    docker@manager:~$ docker stack services vote
    Nothing found in stack: vote
    
  4. Run docker node ls to verify that the swarm is still active on both nodes.

    docker@manager:~$ docker node ls
    ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
    1q0nmgrvbfk9kwj3r9lo85l94 *  manager   Ready   Active        Leader
    a4zgsyk5upjfc4g6dv89seq69    worker    Ready   Active      
    

    You can re-use the swarm in a number of ways, such as redeploy this or another application, try a simple use case to deploy a single service to a swarm, or explore or reconfigure the swarm.

Removing the machines

If you don’t need this swarm anymore and prefer to remove your local machines altogether, use docker-machine rm to do so. (Or, docker-machine rm -f will force-remove running machines.)

$ docker-machine rm worker
About to remove worker
WARNING: This action will delete both local reference and remote instance.
Are you sure? (y/n): y
Successfully removed worker

$ docker-machine rm manager
About to remove manager
WARNING: This action will delete both local reference and remote instance.
Are you sure? (y/n): y
Successfully removed manager

The Docker images you pulled were all running on the virtual machines you created (either local or cloud), so no other cleanup of images or processes is needed once you stop and/or remove the virtual machines.

What’s next?

See the Docker Machine topics for more on working with docker-machine.

Check out the list of resources for more on Docker labs, sample apps, and swarm mode.

chat icon Feedback? Suggestions? Can't find something in the docs?
Edit this page Request docs changes Get support