Skip to content

Instantly share code, notes, and snippets.

@ladyrassilon
Created June 3, 2015 20:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ladyrassilon/31fa6877a9c24ae4e8f0 to your computer and use it in GitHub Desktop.
Save ladyrassilon/31fa6877a9c24ae4e8f0 to your computer and use it in GitHub Desktop.
Add this to your bash script to avoid docker-machine env dev blocking your bash if dev isn't running
docker_running=$(docker-machine ls | grep dev)
if [[ "$docker_running" == *"Stopped"* ]]
then
echo "fyi - docker not running"
elif [[ "$docker_running" == *"Running"* ]]
then
eval "$(docker-machine env dev)"
fi
@ladyrassilon
Copy link
Author

I was seeing a situation where my bash console wasn't loading because docker-machine env dev wasn't returning because dev wasn't running, so I did a conditional check on the state of whether dev docker-machine was running, before doing the eval.

The fyi statement isn't vital, I just found it informative for me.

@anthonator
Copy link

👍

@oleksandr-diudiun
Copy link

👍
now I use something like this

docker_running=$(docker-machine ls | grep dev)
if [[ "$docker_running" == *"Stopped"* ]]
then
    docker-machine start dev
    eval "$(docker-machine env dev)"
    env | grep "DOCKER_HOST"
elif [[ "$docker_running" == *"Running"* ]]
then
    eval "$(docker-machine env dev)"
fi

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