Setup Docker on OS X

Run Docker from Behind Proxy

Wiki

Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of operating-system-level virtualization on Linux. Docker uses the resource isolation features of the Linux kernel such as cgroups and kernel namespaces, and a union-capable filesystem such as aufs and others to allow independent "containers" to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines.

Official Website docker.com

Difference Between Docker and Vagrant

Vagrant and Docker are different beasts. Docker is a two part shell/management layer for building and running virtual linux containers, based on lxc.

The great thing about Docker is that it is light-weight (because it relies on shared-kernel linux containers) and it is distribution agnostic. While the kernel between all instances is shared (but isolated from the host and each other), the user space for different instances can be based on different linux distributions.

Vagrant on the other hand is a wonderful tool for automatically provisioning multiple virtual machines each with their own configurations managed with puppet and/or chef. For its virtualisation it can use different providers. Originally the default provider was virtualbox, but it now supports many more, including vmware fusion and even amazon-ec2. (From Quora)

This topic discussed the Should to use Vagrant or Docker.io for creating an isolated environment.

You can reference offical documents. In this post, I record my installation process.

Environment Versions

OS X El Capitan Version 10.11.4 (15E65)
Docker Version 1.10.3

OS X users use Docker Toolbox to install Docker software. Docker Toolbox includes the following Docker tools:

  • Docker CLI client for running Docker Engine to create images and containers
  • Docker Machine so you can run Docker Engine commands from Mac OS X terminals
  • Docker Compose for running the docker-compose command
  • Kitematic, the Docker GUI
  • the Docker QuickStart shell preconfigured for a Docker command-line environment
  • Oracle VM VirtualBox

Download and install Docker Toolbox. Lanuch Docker Quickstart Terminal after Docker Toolbox has been installed, it will:

  • create a new (or start an existing) Docker Engine host running
  • switch your environment to your new VM
  • use the docker client to create, load, and manage containers

Process output

bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'
Last login: Wed Mar 23 15:51:39 on ttys002
MacBook Pro:~ xuri$ bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'
Running pre-create checks...
Creating machine...
(default) Copying /Users/xuri/.docker/machine/cache/boot2docker.iso to /Users/xuri/.docker/machine/machines/default/boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: /usr/local/bin/docker-machine env default


                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/


docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

MacBook Pro:~ xuri$

OS X, Boot2Docker and Container architecture diagram


+------------------------------------+            +--------------------------+
|               OS X                 |            |       VirtualBox-VM      |
|                                    |  Connect   |      Tiny Core Linux     |
|               +-----------------+  | (tcp:4243) |  +--------------------+  |
|               |                 |  |            |  |                    |  |
|               |  docker-client  +--+------------+->|   docker-daemon    |  |
|               |                 |  |            |  |                    |  |
|               +-----------------+  |            |  +----------+---------+  |
|                                    |            |             |            |
| +--------------------------------+ |            |             |  run       |
| |           boot2docker          | |            |             v            |
| | ~/.boot2docker                 | |            |  +----------------+      |
| |      |                         | | Boot up to |  | +--------------+-+    |
| |      +----> boot2docker.iso    |-+----------->|  | | +--------------+-+  |
| |      |                         | |            |  +-+ |                |  |
| |      +----> boot2docker->m.vmdk| |            |    +-+  lxc process   |  |
| |      |                         | |            |      |                |  |
| +--------------------------------+ |            |      +----------------+  |
+------------------------------------+            +--------------------------+


Some Docker commands

Check Docker version and info

$ docker version

Docker Information

$ docker info

Images operation

Show all top level images, their repository and tags, and their size:

$ docker images

Search Docker Hub for images:

$ docker search <image_name>

Pull an image or a repository from the registry:

$ docker pull <image_name>

Remove one or more images:

$ docker rmi <image_name>

Save an image(s) to a tar archive (streamed to STDOUT by default):

$ docker save <image_name> > <filename.tar>

Write to a file, instead of STDOUT:

$ docker save -o <filename.tar> <filename>

Create an empty filesystem image and import the contents of the tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it:

$ docker import <file|URL>

Loads a tarred repository from a file or the standard input stream. Restores both images and tags:

$ docker load < <filename.tar>

Container operation

Run a command in a new container:

$ docker run <image_name> [command] [arg]

Enter the container:

$ docker run -i -t <image_name> /bin/bash

Enter the container last time entered:

$ docker exec -i -t <container ID>

Shows just running containers:

$ docker ps

Show all containers:

$ docker ps -a

Show n last created containers (includes all states):

$ docker ps -l

Commit a container:

$ docker commit <container ID> <new_image_name>

Related Article Run Docker from Behind Proxy

Setup Docker on OS X
50 votes, 4.48 avg. rating (89% score)