Mac部署Docker环境

参考

各种版本Docker安装官方文档。

相关系统信息

OS X EI Captian 10.11
Oracle VM VirtualBox 4.3
docker-machine version 0.4.1 (e2c88d6)
Docker version 1.8.3, build f4bf5c7

安装说明

Docker项目的目标是实现轻量级的操作系统虚拟化解决方案。 Docker的基础是Linux 容器(LXC)等技术。
这里我们要在Mac上部署Docker,所以Docker的基础是 Linux这句话尤其重要,官方文档两个配图很直观的反应了这个问题。

Linux:

Mac部署Docker环境_第1张图片
Docker Linux

MacX:

Mac部署Docker环境_第2张图片
Docker MacX

MacX通过docker-machine在一个Linux虚拟机中运行Docker Daemon。
docker-machine是用来创建和管理Linux虚拟机(Docker Daemon运行的基础)的工具,MacX使用Oracle VM VirtualBox来虚拟Linux,这里需要注意Oracle VM VirtualBox的版本最好为4.3版本,我在部署过程中使用最新的Oracle VM VirtualBox5.0,发现跟着官方文档往下无法启动default虚拟机,具体原因Google一堆,目前没有查清楚。
下面详细说明如何部署。

部署步骤

根据官方最新(截止本文发布时2015/10/15)文档,MacX平台使用Docker Toolbox来引导安装Docker。

The Docker Toolbox installer includes the following: 
    •   Docker Client docker binary 
    •   Docker Machine docker-machine binary 
    •   Docker Compose docker-compose binary 
    •   Kitematic - Desktop GUI for Docker 
    •   Docker Quickstart Terminal app

The binaries are installed in the /usr/local/bin directory. 
  1. 点击下载最新版本Docker Toolbox pkg,并一路点击continue进行安装
  2. 当进行到如下界面时(安装的倒数第二步),你可以选择点击左边的Docker Quickstart Terminal.app通过命令行来创建第一个默认名为default的Linux虚拟机,也可以点击右边的Kitematic (Beta).app通过一个界面来创建他。


    Mac部署Docker环境_第3张图片
    安装的倒数第二步
  3. 第二步如果点击两个都无法创建Linux虚拟机的话,可以暂时跳过,只要保证有可用的Oracle VM VirtualBox的前提下,可以在命令行使用docker-machine create --driver virtualbox default命令创建
  4. 安装成功会在对话框你们看到如下信息
Installation Successful!
Upgrade your VM:
    1.  Open a Terminal window.
    2.  Enter the following command: 
docker-machine upgrade default

运行 HelloWorld

使用docker-machine ls命令查看当前Linux虚拟机列表

 ~/ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL   SWARM
default            virtualbox   Stopped

docker-machine start default 命令运行default虚拟机,进入虚拟机后运行hello-world容器来验证安装

docker-machine start default
docker-machine ssh default
docker run hello-world

以下是一个完整的运行过程

 ~/ docker-machine create --driver virtualbox default
Creating VirtualBox VM...
Creating SSH key...
Starting VirtualBox VM...
Starting VM...
To see how to connect Docker to this machine, run: docker-machine env default
 ~/ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
default            virtualbox   Running   tcp://192.168.56.101:2376
 ~/ docker run hello-world
Post http:///var/run/docker.sock/v1.20/containers/create: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?
 ~/ docker-machine ssh default
                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.8.3, build master : af8b089 - Mon Oct 12 18:56:54 UTC 2015
Docker version 1.8.3, build f4bf5c7
docker@default:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b901d36b6f2f: Pull complete
0a6ba66e537a: Pull complete
Digest: sha256:517f03be3f8169d84711c9ffb2b3235a4d27c1eb4ad147f6248c8040adb93113
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/userguide/

此部分仅讲述如何部署Docker,具体使用后面的文章继续跟进。欢迎关注。

你可能感兴趣的:(Mac部署Docker环境)