码迷,mamicode.com
首页 > 其他好文 > 详细

daocloud创建虚拟机及连接bluemix

时间:2017-06-24 22:51:36      阅读:539      评论:0      收藏:0      [点我收藏+]

标签:local   而且   amp   sage   registry   failed   master   login   chm   

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

    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里面的版本号)

      正确的命令:

      ubuntu@ip-10-23-22-176:~$ docker run michelesr/docker-tutorial ls
      Dockerfile
      README.md
      app.py
      docker-compose.yml
      frontend.js
      index.html
      slide.pdf
      ubuntu@ip-10-23-22-176:~$ 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
      ubuntu@ip-10-23-22-176:~$ docker commit 323 mydocker
      sha256:13b8683acac5e5ba30050d933f2f33cd655d6ea27f94c0cea07904dcc9d56214
      ubuntu@ip-10-23-22-176:~$


      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

      ubuntu@ip-10-23-22-176:~$ 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.


      ubuntu@ip-10-23-22-176:~$ bluemix logout
      Logging out...
      OK
      ubuntu@ip-10-23-22-176:~$ bluemix login -a https://api.eu-gb.bluemix.net
      API endpoint: https://api.eu-gb.bluemix.net

      Email> zhangjiem@outlook.com

      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:           zhangjiem@outlook.com  
      Account:        hbfec (516262f97a0b3d02a986db99d5b45cd3)  
      Org:            cloudplace  
      Space:          mycloud  
      ubuntu@ip-10-23-22-176:~$ 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

      ubuntu@ip-10-23-22-176:~$ 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

      标签:local   而且   amp   sage   registry   failed   master   login   chm   

      原文地址:http://www.cnblogs.com/zhangjiem/p/7074496.html

      (0)
      (0)
         
      举报
      评论 一句话评论(0
      登录后才能评论!
      © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
      迷上了代码!