在OS X安裝Docker

在學習Docker的過程當中仔細的閱讀了官方的入門教程, 爲加深學習的印象, 翻譯此教程, 也同時方便他人學習使用.linux

目錄

Mac OS X用戶使用Docker Toolbox安裝Docker軟件, Docker Toolbox包含了下列的Docker 工具:docker

  • Docker CLI客戶端, 用來運行Docker Engine,並建立鏡像和容器
  • Docker Machine, 在Mac OS X終端運行Docker Engine命令
  • Docker Compose, 用來運行docker-compose命令
  • Kitematic, Docker圖形用戶界面
  • Docker QuickStart, 快速啓動Docker命令行環境的shell
  • Oracle VM VirtualBox

因爲Docker Engine守護進程使用特定的Linux內核的功能, 你沒法再本地的OS X運行Docker Engine, 與之代替的是你必須使用Docker Machine命令docker-machine在你本地的機器建立並鏈接一個小型的linux虛擬機. 這個就在你Mac上的虛擬主機就是Docker Machine.shell

第一步,檢查版本

你的Mac必須運行OS X 10.8 「Mountain Lion」或以上的系統才能運行Docker, 你能夠這樣查看OS的版本:json

  1. 從蘋果菜單中選擇」關於本機」
    這裏寫圖片描述
  2. 若是你的版本正確,就能夠進行下一步了
    若是你沒有使用支持的版本,你須要考慮先升級的你操做系統

第二步,安裝Docker Toolbox

  1. 訪問Docker Toolboxubuntu

  2. 點擊下載連接bash

  3. 經過雙擊下載的安裝包, 或者右鍵安裝包在彈出的菜單中選擇」打開」, 來安裝Docker Toolboxapp

    安裝程序將啓動一個介紹對話框,介紹安裝內容的概述。ide

    這裏寫圖片描述

  4. 點擊」繼續」安裝toolbox工具

    安裝程序爲你提供了選項, 自定義標準安裝學習

    這裏寫圖片描述

    默認的, 標準的Docker Toolbox安裝:

    • 爲Docker 工具在/usr/local/bin安裝二進制文件
    • 使這些二進制文件對全部用戶可用
    • 更新已經存在的Virtual Box

    現階段, 不要修改任何的默認選線

  5. 點擊」安裝」, 執行標準安裝

    系統會提示你輸入密碼

    這裏寫圖片描述

  6. 輸入你的密碼, 繼續完成安裝

    當它完成後,安裝程序提供了一些快捷鍵。您能夠忽略此爲如今和點擊繼續。

    這裏寫圖片描述

    點擊」關閉」結束安裝

    這裏寫圖片描述

第三步, 驗證安裝

爲了運行一個Docker容器, 你須要:

  • 建立一個新的(或者開始一個已經存在的)Docker Engine 主機
  • 從你的環境切換到新的VM環境
  • 使用Docker客戶端建立, 加載, 管理容器

一旦你建立了Docker machine, 你能夠想任何一個Virtual Box VM同樣隨時使用它, 它會保持你使用後的相關配置.

  1. 打開Launchpad, 找到Docker Quickstart Terminal圖標
    這裏寫圖片描述

  2. 點擊Docker Quickstart Terminal圖標, 打開一個窗口.

    終端會作一系列的事情來爲你設置Docker Quickstart Terminal

    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. 在終端窗口上點擊鼠標用來激活

    若是你不熟悉終端窗口,這裏有一些快速提示。

    這裏寫圖片描述

    該提示是傳統的$美圓符號。你輸入命令在命令行這是提示後的區域。您的光標被突出顯示的區域或指示|出如今命令行。鍵入命令後,一直按回車鍵。

  4. 鍵入命令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/

尋找故障排除幫助?

一般狀況下,上述步驟工做外的開箱,但某些狀況下可能會出現問題。若是你的Docker運行的hello-world沒有工做,出現了錯誤,請查看故障排除快速修復常見問題。

下一步去哪裏?

此時, 您已成功安裝了Docker軟件. 離開Docker Quickstart Terminal窗口. 如今, 進入下一個頁面, 閱讀一個很是簡短的介紹, [Docker鏡像和容器]

相關文章
相關標籤/搜索