Docker has instructions for installation on their site (mac, windows, linux).
If you are running Docker for the first time on OS X or Windows, you'll need to install docker-machine and VirtualBox. On Mac, our recommended approach is through homebrew.
brew install docker
brew install docker-machine
brew cask install virtualbox
Once you have Docker installed, create a virtual machine:
$ docker-machine create --driver virtualbox default
# Add relevant environment variables to your shell
# (if you don't use bash, replace with `.zshrc`, `.profile`, etc.
$ echo 'eval $(docker-machine env)' >> ~/.bashrc && source ~/.bashrc
# Open up port 3000 between the host and the virtualbox machine
$ VBoxManage modifyvm "default" --natpf1 "guestnginx,tcp,,3000,,3000"
$ docker run --rm hello-world
# should print something like:
Hello from Docker!
This message shows that your installation appears to be working correctly.
...