2 minute read 12 Sep 2016

DEPRECATED! - this guide is using Docker Toolbox instead of the new native Docker for Windows/Mac so it is not actual anymore.

When working on Site Stacker, or any other distributed application, it’s a very good idea to use Docker to help you build and run your applications with zero configuration and in seconds.

This guide explains how to install and configure your shell to use docker commands, especially on Mac OS X and Windows where you need extra steps since Docker only runs on Linux.

If you’re a non-technical user interested in learning about Docker, you should read these very explanatory and easy to follow guides, based on your platform:

Check if Docker is running

In your shell (Terminal, PowerShell, etc.), run:

docker info

If you get Command not found, you probably need to install Docker.

If you get An error occurred trying to connect or similar, you need to make sure Docker VM is up and running and your shell is properly configured.

Install Docker

Start Docker

This is only needed on Mac OS X and Windows. Linux users run Docker natively.

The easiest method is to open Docker Quickstart Terminal (:exclamation: On Windows, run it as Administrator), which should start the VM automatically and configure your shell.

If this doesn’t work for some reason, or your prefer not to use Docker Quickstart Terminal (maybe to use PowerShell instead of the bash shell on Windows), start the vm and configure your shell for docker manually.

:thumbsup: You’re done! You can now run docker commands. Check the Appendix below for other tips.

Appendix

Docker Quickstart Terminal

Using Docker Quickstart Terminal is the recommended way to use Docker on Windows and Mac OS X. This is because when you open it, it makes sure your VM is running and you can start using docker commands right away.

Docker Quickstart Terminal on Windows

Shortcut bash.exe not found

Missing Shortcut

If the Docker Quickstart Terminal doesn’t start and complains about a missing shortcut, make sure the Target field in the shortcut Properties has the correct path to the Git Bash, e.g.:

Property Value
Target C:\Users\USERNAME\AppData\Local\Programs\Git\bin\bash.exe --login -i "C:\Program Files\Docker Toolbox\start.sh"

* Replace USERNAME with your user.
* Make sure the path to Git Bash is correct, change it accordingly.

Run Docker Quickstart Terminal as administrator

On Windows, to make it even easier to work with, configure it to always run as Administrator, so you don’t have to do it each time:

Start the VM

This is only necessary if you’re not using Docker Quickstart Terminal.

You can check if the VM is running using docker-machine status (:exclamation: On Windows, run PowerShell as Administrator):

$ docker-machine status default
Stopped

If it’s stopped, start it using docker-machine start:

$ docker-machine start default
Starting "default"...
(default) Waiting for an IP...
Machine "default" was started.
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

Configure your shell for docker

This is only necessary if you’re not using Docker Quickstart Terminal.

If the VM is running but you still can’t run docker info without errors, it’s probably because your shell doesn’t know how to connect to the VM.

You can configure your shell (Terminal on OS X or PowerShell on Windows) by running the appropriate command printed by docker-machine env:

==Windows==

$ docker-machine env default
$Env:DOCKER_TLS_VERIFY = "1"
$Env:DOCKER_HOST = "tcp://192.168.99.100:2376"
$Env:DOCKER_CERT_PATH = "C:\Users\Calin\.docker\machine\machines\default"
$Env:DOCKER_MACHINE_NAME = "default"
# Run this command to configure your shell:
# & "C:\Program Files\Docker Toolbox\docker-machine.exe" env default | Invoke-Expression
& "C:\Program Files\Docker Toolbox\docker-machine.exe" env default | Invoke-Expression

==/Windows==

==Mac==

$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/calin/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval "$(docker-machine env default)"
eval "$(docker-machine env default)"

==/Mac==

To check if it worked, run docker info and make sure it runs without errors.

Upgrade Docker

If you want to upgrade Docker on your system, you can check the current version using docker version:

$ docker version
Client:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   a34a1d5
 Built:        Fri Nov 20 17:56:04 UTC 2015
 OS/Arch:      windows/amd64

Server:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   a34a1d5
 Built:        Fri Nov 20 17:56:04 UTC 2015
 OS/Arch:      linux/amd64

On Max OS X and Windows, you can upgrade Docker by re-installing the Docker Toolbox.