Skip to content

Instantly share code, notes, and snippets.

@jdickey
Last active December 1, 2017 09:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdickey/0c47b391109f857bba2dddee204a72e0 to your computer and use it in GitHub Desktop.
Save jdickey/0c47b391109f857bba2dddee204a72e0 to your computer and use it in GitHub Desktop.
Basic workflow for docker-machine on Mac with VMWare Fusion
#!/bin/bash
# This is a fork of https://gist.github.com/mcemce/a6ee9b4ab07df9972883 with
# additional variable-based configuration and status hand-holding added by
# myself (@jdickey). Thanks to @mcemce for helping me out of a jam.
# Docker VM name. 'dev' is a recommended name for a development VM; you'll want
# to name a production VM something else.
OUR_DOCKER_VM=dev
echo "Docker will install a machine named $OUR_DOCKER_VM within VMware."
# VM RAM size, in MB
OUR_MEMORY_SIZE=2048
echo "Docker will create the VMware machine with $OUR_MEMORY_SIZE MB of RAM."
# Get everything ready on a Mac, ensuring latest Docker
echo "Updating and upgrading Homebrew, then installing Docker if not already installed."
brew update && brew upgrade && brew cleanup && brew install docker docker-machine docker-compose
# Docker's installed; what version is it?
PARTS=`brew list docker | head -1 | sed 's,/, ,g'`
PART_INDEX=`echo $PARTS | wc -w | sed 's/ //g'`
PART_INDEX=`expr $PART_INDEX - 1`
OUR_DOCKER_VERSION=`echo $PARTS | cut -d ' ' -f $PART_INDEX`
unset OUR_VMWARE_B2D_URL
# Uncomment this if and *only if* you want to hard-code a specific Boot2Docker
# version (defaulting to match the current Docker version). By doing so, *YOU
# ASSUME RESPONSIBILITY FOR MANUAL UPGRADES AND REPAIRING VERSION MISMATCHES.*
# OUR_VMWARE_B2D_URL="--vmwarefusion-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v$OUR_DOCKER_VERSION/boot2docker.iso"
# Create a new machine. By default, we *do not* specify the
# --vmwarefusion-boot2docker-url option, as doing so locks us to a particular
# Boot2Docker version and disables automatic updates. This will eventually cause
# Docker to break. If, on the other hand, you wish to do so, uncomment the
# assignment immediately above this comment.
docker-machine create --driver vmwarefusion --vmwarefusion-memory-size $OUR_MEMORY_SIZE $OUR_VMWARE_B2D_URL $OUR_DOCKER_VM
# Bring the machine up if not already running. Creating a machine should auto-
# start it.
# docker-machine start $OUR_DOCKER_VM
# Configure Shell
eval $(docker-machine env $OUR_DOCKER_VM)
# Get VMs IP
echo "Machine '$OUR_DOCKER_VM' now active at IP $(docker-machine ip $OUR_DOCKER_VM)"
# SSH to VM as desired.
# docker-machine ssh $OUR_DOCKER_VM
# Bring machine down
# docker-machine stop $OUR_DOCKER_VM
# Clean up
unset OUR_MEMORY_SIZE
unset OUR_DOCKER_VM
unset OUR_VMWARE_B2D_URL
unset PARTS PART_INDEX OUR_DOCKER_VERSION
unset OUR_VMWARE_B2D_URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment