The above failure happens when the ‘manager’ docker machine is not active; as a result, the new node machine will not be able to join the swarm cluster.
To fix this:
Step 1: Check for the active machine hosts as:
$ docker-machine active
Step 2: Activate the ‘manager’ machine as:
$ eval $(docker-machine env manager)
$ docker-machine active
Step 3: Get the swarm join token as worker
$docker swarm join-token worker
Step 4: Connect to the worker machine say: worker2 [ To create docker node machines as worker: join node as a worker ]
$docker-machine ssh worker2
Step 5: Run the swarm join token command; it will be successful.