docker-machine
Regular running on MacOS
# Put this in ~/.zshrc so you don't have to run manually
$ eval "$(docker-machine env default)"
$ docker-machine start default
$ docker-machine stop default
Connecting to containers on MacOS
If you’re unable to connect to the Docker container from a browser on MacOS, you’ll want to read this.
When docker runs containers using docker-machine, the ports that get exposed are on the virtualbox instance and not on your mac. So rather than being able to access containers on localhost with the port, you have to use the IP address of the virtualbox instance instead. Here’s an example with a standard nginx instance.
docker run -d -p 9000:80 --name webserver nginx
curl -i localhost:9000 <-- this will NOT work
curl -i $(docker-machine ip default):9000 <-- this will work
Getting started on MacOS
$ brew install docker docker-machine
$ brew cask install virtualbox
# Will need to provide admin password
# Will need to do step again after allowing extension install
$ docker-machine create --driver virtualbox default
$ docker-machine env default
$ eval "$(docker-machine env default)"
$ docker run hello-world
$ docker-machine stop default