Mac OSX Docker 教程 (一)

本文基于Docker官方网站的Mac OSX教程所写。

安装Docker Toolbox

Docker Toolbox包含如下的Docker工具:

  • Docker CLI 用于创建Docker镜像和Docker容器
  • Docker Machine 让你可以在Mac OSX以命令行的方式操作Docker引擎
  • Docker Compose用于运行docker-compose命令
  • Kitematic —— Docker的GUI组件
  • Docker快速启动shell
  • Oracle VM 虚拟机

步骤一:检查系统版本号

检查操作系统版本号,版本号必须 >= 10.8

步骤二:安装Docker Tool

下载Docker Toolbox并开始进行安装,安装很傻瓜,一路next就可以。

步骤三:检查是否安装成功

  1. 首先开启Docker Quickstart Terminal

  2. 终端会有如下输出

    Last login: Sat Jul 11 20:09:45 on ttys002
    bash '/Applications/Docker Quickstart Terminal.app/Contents/Resources/Scripts/    start.sh'
    Get http:///var/run/docker.sock/v1.19/images/json?all=1&filters=%7B%22dangling%22%3A%5B%22true%22%5D%7D: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
    Get http:///var/run/docker.sock/v1.19/images/json?all=1: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
    -bash: lolcat: command not found
    
    mary at meepers in ~
    $ bash '/Applications/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh'
    Creating Machine dev...
    Creating VirtualBox VM...
    Creating SSH key...
    Starting VirtualBox VM...
    Starting VM...
    To see how to connect Docker to this machine, run: docker-machine env dev
    Starting machine dev...
    Setting environment variables for machine dev...
    
                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/
    
    The Docker Quick Start Terminal is configured to use Docker with the “default” VM.
    
  3. 键入docker run hello-world

    $ docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    535020c3e8ad: Pull complete
    af340544ed62: Pull complete
    Digest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c
    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 Engine CLI client contacted the Docker Engine daemon.
    2. The Docker Engine daemon pulled the "hello-world" image from the Docker Hub.
    3. The Docker Engine daemon created a new container from that image which runs the executable that produces the output you are currently reading.
    4. The Docker Engine daemon streamed that output to the Docker Engine CLI 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/