I'm using docker-machine
to manage my cloud servers. I'm writing some bash scripts to automate some tasks. The question is: "How to check in bash script if docker machine with the specific name already exists?". I need some expression to return true if it exists and false if it doesn't.
Thanks
Just run it through grep, if a regexp is good enough for you. For example if you have a machine called foo:
$ docker-machine ls -q | grep '^foo$'
Should work and return 0. The caret matches the start of the line and the space avoids partial matches. If it doesn't match you will get a non-zero return code.
You can use something like the following:
docker-machine status some-machine 2> /dev/null || echo "Machine does not exists"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With