1. 程式人生 > >daocloud創建虛擬機及連接bluemix

daocloud創建虛擬機及連接bluemix

ocs cati 進制 commit 指定 下載速度 host name 執行 網站

1. daocloud提供免費的虛擬機服務,但是只能使用兩個小時。

創建過程記錄如下:

打開daocloud儀表板網頁https://dashboard.daocloud.io/cluster

技術分享

點擊添加主機,然後在新的界面選擇免費試用膠囊主機,免費試用兩個小時主機。點擊一鍵接入自動創建一個ubuntu環境,默認的是14.04.2,帶docker環境。

  • 膠囊主機自帶 Docker 運行環境,並自動接入 DaoCloud 容器管理平臺。
  • 每個膠囊主機可以免費體驗 120 分鐘。到期後自動消失,也可以再次體驗。
  • 發布到膠囊主機中的應用信息會保留並可以自動遷移。

另外界面有使用自己的主機怎樣添加docker,使用daocloud提供的鏡像,加快下載速度。

http://get.daocloud.io/#install-docker

2. 在 Linux上 安裝 Docker

    Docker 的 安裝資源文件 存放在Amazon S3,會間歇性連接失敗。所以安裝Docker的時候,會比較慢。
    你可以通過執行下面的命令,高速安裝Docker。

    curl -sSL https://get.daocloud.io/docker | sh

    適用於Ubuntu,Debian,Centos等大部分Linux,會3小時同步一次Docker官方資源

    安裝體驗版或測試版,體驗最新Docker。

    curl -sSL https://get.daocloud.io/docker-experimental | sh
    curl -sSL https://get.daocloud.io/docker-test | sh

    如果安裝不成功,可以選擇使用二進制包安裝方式。 下載二進制包

    卸載Docker

    • Ubuntu|Debian
    • RHEL|CentOS
    • Fedora
    sudo apt-get remove docker docker-engine

    卸載Docker後,/var/lib/docker/目錄下會保留原Docker的鏡像,網絡,存儲卷等文件. 如果需要全新安裝Docker,需要刪除/var/lib/docker/目錄

    rm -fr /var/lib/docker/
    安裝 Docker Compose

      Docker Compose 存放在Git Hub,不太穩定。
      你可以也通過執行下面的命令,高速安裝Docker Compose。

      curl -L https://get.daocloud.io/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
      chmod +x /usr/local/bin/docker-compose

      你可以通過修改URL中的版本,可以自定義您的需要的版本。


      查看新建的主機

      技術分享

      如圖,ssh登錄ip地址為54.223.127.182,用戶名為ubuntu,密碼: 837ec6d689963000

      使用ssh登錄連接。默認docker環境為1.13版本。

      技術分享

      3. docker常用命令

      搜索可用的docker鏡像

      使用docker最簡單的方式莫過於從現有的容器鏡像開始。Docker官方網站專門有一個頁面來存儲所有可用的鏡像,網址是:index.docker.io。你可以通過瀏覽這個網頁來查找你想要使用的鏡像,或者使用命令行的工具來檢索。

      目標:

      學會使用命令行的工具來檢索名字叫做tutorial的鏡像。

      提示:

      命令行的格式為:docker search 鏡像名字

      正確的命令:

      $docker search tutorial

      學會使用docker命令來下載鏡像

      下載鏡像的命令非常簡單,使用docker pull命令即可。(譯者按:docker命令和git有一些類似的地方)。在docker的鏡像索引網站上面,鏡像都是按照用戶名/鏡像名的方式來存儲的。有一組比較特殊的鏡像,比如ubuntu這類基礎鏡像,經過官方的驗證,值得信任,可以直接用鏡像名來檢索到。

      目標:

      通過docker命令下載tutorial鏡像。

      提示:

      執行pull命令的時候要寫完整的名字,比如"learn/tutorial"。

      正確的命令:

      $docker pull docker-tutorial

      不帶tag默認下載latest版本。下載得一段時間,大概下載了300M多吧,好幾個包。環境是debian jessie。

      技術分享

      技術分享

      $docker run michelesr/docker-tutorial echo "hello world"

      運行測試,輸出hello world


      $docker run michelesr/docker-tutorial apt-get install ping

      $docker run michelesr/docker-tutorial ping www.baidu.com

      添加ping命令,ping測試下,不過默認是已經有ping命令了,而且ping一直沒有輸出,我按Ctrl+C停止了才輸出ping結果。ping google悲劇。

      技術分享

      $docker run michelesr/docker-tutorial wget http://mirrors.163.com/.help/sources.list.jessie

      更改鏡像源,失敗。下載完成了當前目錄找不到下載的文件。不知道為什麽。

      保存對容器的修改

      當你對某一個容器做了修改之後(通過在容器中運行某一個命令),可以把對容器的修改保存下來,這樣下次可以從保存後的最新狀態運行該容器。docker中保存狀態的過程稱之為committing,它保存的新舊狀態之間的區別,從而產生一個新的版本。

      目標:

      首先使用docker ps -l命令獲得安裝完ping命令之後容器的id。然後把這個鏡像保存為learn/ping。

      提示:

      1. 運行docker commit,可以查看該命令的參數列表。

      2. 你需要指定要提交保存容器的ID。(譯者按:通過docker ps -l 命令獲得)

      3. 無需拷貝完整的id,通常來講最開始的三至四個字母即可區分。(譯者按:非常類似git裏面的版本號)

      正確的命令:

      [email protected]:~$ docker run michelesr/docker-tutorial ls
      Dockerfile
      README.md
      app.py
      docker-compose.yml
      frontend.js
      index.html
      slide.pdf
      [email protected]:~$ docker ps -l
      CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
      3238c5cf61af michelesr/docker-tutorial "ls" 5 seconds ago Exited (0) 5 seconds ago friendly_euclid
      [email protected]:~$ docker commit 323 mydocker
      sha256:13b8683acac5e5ba30050d933f2f33cd655d6ea27f94c0cea07904dcc9d56214
      [email protected]:~$


      4. 安裝BlueMix工具並建立容器

      wget https://public.dhe.ibm.com/cloud/bluemix/cli/bluemix-cli/Bluemix_CLI_0.5.4_amd64.tar.gz

      tar xvf Bluemix_CLI_0.5.4_amd64.tar.gz

      sudo ./install_bluemix_cli

      安裝 Bluemix Containers 插件

      bluemix plugin install IBM-Containers -r Bluemix

      bluemix login -a https://api.eu-gb.bluemix.net

      bluemix ic init

      [email protected]:~$ bluemix ic init
      Deleting old configuration file...
      open /home/ubuntu/.cf/config.json: no such file or directory
      Generating client certificates for IBM Containers...
      {
      "code": "IC5076E",
      "description": "The namespace has not yet been specified. A namespace must be set for your organization before you can work with IBM Containers and cannot be changed once set. You can use \u2018bx ic namespace-set NAMESPACE‘ to set the namespace.",
      "environment": "prod-lon02",
      "host_id": "20",
      "incident_id": "773-1498307949.590-603156",
      "name": "NamespaceNotSpecified",
      "rc": "404",
      "type": "Infrastructure"
      }
      FAILED
      Your login state might have expired. Use ‘bluemix login‘ to login again.


      [email protected]:~$ bluemix logout
      Logging out...
      OK
      [email protected]:~$ bluemix login -a https://api.eu-gb.bluemix.net
      API endpoint: https://api.eu-gb.bluemix.net

      Email> [email protected]

      Password>
      Authenticating...
      OK

      Select an account (or press enter to skip):
      1. hbfec (516262f97a0b3d02a986db99d5b45cd3)
      Enter a number> 1
      Targeted account hbfec (516262f97a0b3d02a986db99d5b45cd3)

      Targeted org cloudplace

      Select a space (or press enter to skip):
      1. mycloud
      2. cloud
      Enter a number> 1
      Targeted space mycloud



      API endpoint: https://api.eu-gb.bluemix.net (API version: 2.75.0)
      Region: eu-gb
      User: [email protected]
      Account: hbfec (516262f97a0b3d02a986db99d5b45cd3)
      Org: cloudplace
      Space: mycloud
      [email protected]:~$ bluemix ic init
      Deleting old configuration file...
      open /home/ubuntu/.cf/config.json: no such file or directory
      Generating client certificates for IBM Containers...
      Client certificates are being stored in /home/ubuntu/.ice/certs/...

      Client certificates are being stored in /home/ubuntu/.ice/certs/containers-api.eu-gb.bluemix.net/24de75dd-90e7-4f9b-b435-d26e9f494f63...

      OK
      Client certificates were retrieved.

      Checking local Docker configuration...
      OK

      Authenticating with registry at host name registry.eu-gb.bluemix.net
      OK
      Your container was authenticated with the IBM Containers registry.
      Your private Bluemix repository is URL: registry.eu-gb.bluemix.net/myname

      You can choose from two ways to use the Docker CLI with IBM Containers:


      Option 1: This option allows you to use ‘bluemix ic‘ for managing containers on IBM Containers while still using the Docker CLI directly to manage your local Docker host.
      Use this Cloud Foundry IBM Containers plug-in without affecting the local Docker environment:


      Example Usage:
      bluemix ic ps
      bluemix ic images

      Option 2: Use the Docker CLI directly. In this shell, override the local Docker environment to connect to IBM Containers by setting these variables. Copy and paste the following commands:
      Note: Only Docker commands followed by (Docker) are supported with this option.
      export DOCKER_HOST=tcp://containers-api.eu-gb.bluemix.net:8443
      export DOCKER_CERT_PATH=/home/ubuntu/.ice/certs/containers-api.eu-gb.bluemix.net/24de75dd-90e7-4f9b-b435-d26e9f494f63
      export DOCKER_TLS_VERIFY=1

      Example Usage:
      docker ps
      docker images

      [email protected]:~$ docker ps
      CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


      bluemix ic namespace get

      docker tag d355ed3537e9 registry.eu-gb.bluemix.net/myname/ubuntu:d355ed3537e9

      docker push registry.eu-gb.bluemix.net/myname/ubuntu:d355ed3537e9

      技術分享

      技術分享


      參考:

      https://www.ibm.com/developerworks/cn/cloud/library/cl-cn-bluemix-containers-udpserver/index.html

      http://blog.csdn.net/evankaka/article/details/50364559

      daocloud創建虛擬機及連接bluemix