Discovering the current environment
docker-machine env default
Ensuring that the instance is stopped
docker-machine stop local
Using this as a check (based upon process return code) and doing something upon failure
docker-machine env default || echo "doesn't exist"
Upon failure... Try starting the machine
docker-machine env local || docker-machine start local
Changing the name to locald - a machine we know does not exist.
Check to see if the machine is running by piping docker-machine ls to egrep.
We then check the return code.
docker-machine ls | egrep "^locald[^R]*[u]*Running.*" > /dev/null
echo $?
We can also get that onto a single line and output a message to indicate the state
docker-machine ls | egrep "^locald[^R]*[u]*Running.*" > /dev/null || echo "not running"
cheers Bryan