Skip to content

Instantly share code, notes, and snippets.

@binarytemple
Last active February 26, 2016 10:49
Show Gist options
  • Save binarytemple/5b70d0d4074c138ced5d to your computer and use it in GitHub Desktop.
Save binarytemple/5b70d0d4074c138ced5d to your computer and use it in GitHub Desktop.

Tutorial

Some helpful automation commands to determine machine state

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"
@ar1g
Copy link

ar1g commented Feb 26, 2016

cheers Bryan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment