Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created November 4, 2015 16:00
Show Gist options
  • Save grahamc/8c496f3a847baa5bfe0b to your computer and use it in GitHub Desktop.
Save grahamc/8c496f3a847baa5bfe0b to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
set -u
readonly MACHINE=dev
if ! docker-machine status $MACHINE > /dev/null 2> /dev/null; then
# The machine doesn't exist
docker-machine create \
--driver virtualbox \
--virtualbox-disk-size 40000 \
--virtualbox-memory 8192 \
$MACHINE 1>&2
fi
if [ "x${1:-}" = "x--restart" ]; then
echo "Stopping $MACHINE for --restart" 1>&2
docker-machine stop $MACHINE 2>&1
fi
if docker-machine status $MACHINE 2> /dev/null | grep -q "Stopped\|Saved" > /dev/null; then
# Machine exists but is stopped
docker-machine start $MACHINE 1>&2
fi
# Eval the configuration
eval $(docker-machine env $MACHINE)
# Echo a correct export command, note: if any of the parameters have spaces
# in it, this will probably not work.
/bin/echo -n "export "
env | grep DOCKER | xargs echo
echo "Ready to go with $MACHINE." 1>&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment