Skip to content

Instantly share code, notes, and snippets.

@ronny
Last active March 30, 2020 20:37
Show Gist options
  • Save ronny/fab629d524f4f21c748f to your computer and use it in GitHub Desktop.
Save ronny/fab629d524f4f21c748f to your computer and use it in GitHub Desktop.

Docker on Mac OS X

These are my notes based on my experience with using Docker on Mac OS X.

Assumptions

If these assumptions are not true for you, then this document may not be for you.

I assume you have these installed:

  • recent-ish Mac OS X
  • VMware Fusion (open it at least once and accept the license if you haven't)
  • Homebrew

Steps

Install the required apps with Homebrew. I chose not to use Docker Toolbox because I don't need Kitematic and VirtualBox, and I'd like to use Homebrew to manage my third party apps.

brew update
brew install docker docker-machine docker-compose

Then create a docker host virtual machine with:

docker-machine create dev --driver vmwarefusion --vmwarefusion-memory-size 2048

The above command will create a machine with the name "dev". I think Kitematic will pick it up and use it, if you'd like to use Kitematic.

For some reason the vmware driver in docker-machine hardcodes the path to VMware Fusion's vmrun to /Applications/VMware Fusion.app/Contents/Library/vmrun, so if you install it elsewhere then running docker-machine create will timeout and fail. One way to work around it is to create a symlink so that the hardcoded path points to vmrun correctly, e.g.

ln -s "/opt/homebrew-cask/Caskroom/vmware-fusion/7.1.1-2498930/VMware Fusion.app" /Applications

Check the status of your docker machines with:

docker-machine ls

Once it's running, you need to export some environment variables to your shell so that the docker command can work properly.

# you need to run this in every shell you want to run `docker` commands
eval $(docker-machine env dev)

Then you're ready to do docker things.

# this will download the ubuntu:14.04 container from Docker Hub first if you don't already have it
docker run ubuntu:14.04 /bin/echo 'Hello world'

Remember that the docker containers will run inside the docker host, which runs inside the vmware virtual machine. So any docker tutorial that instructs you to connect to localhost will probably not work for you, you need to change it with the IP address of the docker host which you can find out with this command (assuming you named your docker host dev):

docker-machine ip dev

Example:

# this will download the `training/webapp` container from Docker Hub first if you don't already have it
# then it will run the python command and docker will daemonize/background the process
# it will map port 5000 on the docker host to port 5000 on the docker container
docker run -d -p 5000:5000 training/webapp python app.py

curl "http://$(docker-machine ip dev):5000"

# to stop the backgrounded container, either use the long ID returned by `docker run` earlier or find it
# using this command:
docker ps

# then stop it
docker stop 6b07d6344627

# you can also stop the docker host
docker-machine stop dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment