If you use Docker frequently, you’ve likely memorized a few repetitive commands…
docker-machine start XyZvirtualMachine
Then you run…
docker-machine env XyZvirtualMachine
…and then you type…
eval $(docker-machine env XyZvirtualMachine)
One does this about a zillion times if there are multiple virtual machines or for other various reasons. I wanted to simplify this repetitive task so I wrote a bash function, thanks to a fumble I posted on Stackoverflow and then an assist by my good friend Troy Howard (@thoward37).
This quick hack consisted of this Github gist.
gimmedocker() { if [ $1 ]; then
docker-machine start $1
docker-machine env $1
eval $(docker-machine env $1)
docker ps -a
fi }
Stick that in your ~/.bash_profile (or ~/.bashrc if you’re on *nix) and you’re good to go. Then at the bash prompt just type in this.
gimmedocker XyZvirtualMachine
BOOM! Less typing for the win!