The Commands

This lesson contains all the relevant Docker swarm commands with brief reminders of what each one does.

  • docker swarm init creates a new swarm. The node that you run the command on becomes the first manager and is switched to run in swarm mode.

  • docker swarm join-token reveals the commands and tokens needed to join workers and managers to existing swarms. To expose the command to join a new manager, use the docker swarm join-token manager command. To get the command to join a worker, use the docker swarm join-token worker command.

  • docker node ls lists all nodes in the swarm and identifies managers and leaders.

  • docker service create creates a new service.

  • docker service ls lists running services in the swarm and gives basic info on the state of the service and any replicas it’s running.

  • docker service ps <service> gives more detailed information about individual service replicas.

  • docker service inspect gives very detailed information on a service. It accepts the --pretty flag to limit the information returned to the most important information.

  • docker service scale lets you scale the number of replicas in a service up and down.

  • docker service update lets you update many of the properties of a running service.

  • docker service logs lets you view the logs of a service.

  • docker service rm deletes a service from the swarm. Use it with caution as it deletes all service replicas without asking for confirmation.

Get hands-on with 1200+ tech skills courses.