win7,win8下面启动docker

 互联网   2016-09-24 10:35   10895 人阅读  0 条评论
简介:在win7或者win8上面启动一个docker容器,你需要: 创建一个Docker虚拟机。(如果已经创建过,可以启动已有的虚拟机。) 将环境切换到虚拟机里面。 使用docker命令来创建,加载或者管理容器。

在win7或者win8上面启动一个docker容器,你需要:


  • 创建一个Docker虚拟机。(如果已经创建过,可以启动已有的虚拟机。)

  • 将环境切换到虚拟机里面。

  • 使用docker命令来创建,加载或者管理容器。

创建了一个虚拟机之后,你可以像其他的virtualbox 虚拟机一样来重用它。

你可以通过三种方式来启动一个容器:quickstart终端、命令行(cmd.exe)或者powershell。

第一种方式:使用快速启动终端(quickstart terminal)

  1. Docker Toolbox安装完毕之后,会在桌面上有一个quickstart terminal的快捷方式。双击,启动:
    > 打开一个终端窗口。
    > 如果没有默认的虚拟机,创建一个,并启动。
    > 将这个终端的环境指向到这个虚拟机。

  2. 运行hello-world容器,来确认环境安装成功。

    $ docker run hello-world Unable 
                            to find image 
                            'hello-world:latest' locally 
                            511136ea3c5a: Pull complete 
                            31cbccb51277: Pull complete
    e45a5af57b00: Pull complete
    hello-world:latest: The image you are pulling has been verified.
    Important: image verification is 
                            a tech preview feature 
                            and should 
                            not be
    relied 
                            
                            on 
                            to 
                            provide 
                            security. 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.
       (Assuming 
                            it was 
                            not already locally available.) 
                            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
    For more examples 
                            and ideas, visit: 
                            http://docs.docker.com/userguide/

第二种方式:使用windows命令行启动(cmd.exe)

  1. 启动windows命令行(cmd.exe)

  2. 将ssh.exe所在的目录添加到PATH变量中。
    docker-machine 命令需要ssh.exe,这个文件可以在mysysgit的bin目录里面找到。(mysysgit是git在windows下面的一个客户端)

                        
                        set 
                        PATH=%                    PATH%;"c:\Program Files (x86)\Git\bin"
  3. 创建一个新的docker虚拟机。

    docker-machine 
                    
                    create 
                    --driver virtualbox my-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 my-                default

    上面这个命令同时还生成了一份配置文件,存储在 c:\users\username\.docker\machine\machines目录。你只需要执行 create命令,然后就可以使用docker-machine命令来对虚机进行start, stop, query以及其他的操作了。

  4. 列出可用的机器

                C:\Users\mary> docker-machine ls
    NAME                ACTIVE   DRIVER       STATE     URL                         SWARM
    my-            default *        virtualbox   Running 
                tcp:
                //192.168.99.101:2376


  5. 为新的虚拟机获得environment 命令:注意这里面的--shell参数是cmd.

            C:        \Users\mary> docker-machine env --shell cmd my-        default
  6. 连接到默认的机器

    C:\Users\mary> 
        eval 
        "    $(docker-machine env my-default)"
  7. 运行hello-world容器

    C:\Users\mary> docker run hello-world

第三种方式:使用powershell

  1. 启动powershell

  2. 将ssh.exe所在目录添加到PATH变量中。

    PS C:\Users\mary> 
    $Env:Path = 
    "${Env:Path};c:\Program Files (x86)\Git\bin"
  3. 创建一个新的虚机。

    PS 
    C:\Users\mary> docker-machine create --driver virtualbox my-default
  4. 列出可用的机器。

    C:\Users\mary> docker-machine ls
    NAME                ACTIVE   DRIVER       STATE     URL                         SWARM
    my-default *        virtualbox   Running 
    tcp://192.168.99.101:2376
  5. 生成环境变量信息

    C:\Users\mary> docker-machine env --shell powershell my-default
  6. 连接到主机

    C:\Users\mary> 
    eval "$(docker-machine env my-default)"
  7. 运行hello-world容器

    C:\Users\mary> docker run hello-world

本文地址:https://dockerworld.cn/?id=191
温馨提示:文章内容系作者个人观点,不代表Docker中文社区对观点赞同或支持。
版权声明:本文为转载文章,来源于 互联网 ,版权归原作者所有,欢迎分享本文,转载请保留出处!

 发表评论


表情

还没有留言,还不快点抢沙发?