本文所属【知识林】:http://www.zslin.com/web/article/detail/2

在Windows中安装Docker需要注意的是:
1、 必须是64位操作系统
2、 已正确开启系统虚拟化
3、 在Windows系统中安装Docker一般仅限于测试阶段,实际的应用最好还是安装在Linux操作系统中,具体安装方法可参照文档《Centos 6.4中安装Docker

检查是否已开启系统虚拟化

Ctrl+Alt+Delete 打开任务管理器 —> 选择性能选项卡即可看到虚拟化的状态,在虚拟化后面跟的是已启用则表示已正常开启,否则未开启。

开启虚拟化的方法:

  • 开机进入BIOS
  • 选择Advanced选项卡
  • 设置Secure Virtual Machine Mode为Enabled

版本注意

进入官网 www.docker.com,点击Download Docker for Windows 即可下载Windows的安装组件,需要注意的是这里下载的Docker不可以安装到Windows8的系统上,此安装程序的最低要求是Windows10。

借助Docker Toolbox

下载Docker Toolbox,这里可以选择苹果和Windows两个版本,现在下载Windows版本的Docker Toolbox,下载下来的文件名是:DockerToolbox-1.11.2.exe ,版本号可能有所不同。

安装Docker Toolbox

安装Docker Toolbox和安装其他Windows程序一样,都是比较单纯的下一步。具体步骤也可以参考官方提供的【Install Docker for Windows】这篇文档

创建Docker主机

安装完Docker Toolbox后需要创建一个Docker的虚拟主机才能正常使用Docker服务。
可以借助docker-machine命令来完成Docker虚拟主机的相关操作:

help 查看帮助信息

active 查看活动的Docker主机

config 输出连接的配置信息

create 创建一个Docker主机

env 显示连接到某个主机需要的环境变量

inspect 输出主机更新信息

ip 获取Docker主机地址

kill 停止某个Docker主机

ls 列出所有管理的Docker主机

regenerate-certs 为某个主机重新成功TLS认证信息

restart 重启Docker主机

rm 删除Docker主机

scp 在Docker主机之间复制文件

ssh SSH到主机上执行命令

start 启动一个主机

status 查看一个主机状态

stop 停止一个主机

upgrade 更新主机Docker版本为最新

url 获取主机的URL

创建Docker虚拟主机,并指定名称为default

docker-machine create -d virtualbox default

当出现:

Running pre-create checks...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v1.12.1
(default) Downloading C:\Users\zsl-pc\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v1.12.1/boot2docker.iso...

表示正在下载boot2docker.iso镜像文件,这个速度会非常慢,这时可以先按Ctrl+C取消安装,把boot2docker.iso文件通过迅雷等下载工具下载下来并放到指定目录(C:\Users\zsl-pc\.docker\machine\cache\,此目录在不同电脑上会有所不同)下再安装。再次运行create创建Docker虚拟主机时就不会再去远程下载,而是使用本地的iso文件了。

从这里可以看出,docker-machine实际是安装了一个虚拟机,跟VMware非常相似,只是这个更轻量级。

安装完成后可以看到:

F:\java\Docker>docker-machine create -d virtualbox default
Running pre-create checks...
Creating machine...
(default) Copying C:\Users\zsl-pc\.docker\machine\cache\boot2docker.iso to C:\Users\zsl-pc\.docker\machine\machines\default\boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(default) Found a new host-only adapter: "VirtualBox Host-Only Ethernet Adapter #2"
(default) Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env default

可使用命令docker-machine ls查看存在的Docker虚拟主机:

F:\java\Docker>docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v1.12.1

设置Docker环境

当运行命令docker images查看本地镜像时出提示:

F:\java\Docker>docker images
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/images/json: open //./pipe/docker_engine: The system cannot find the file specified.

说明Docker-machine的环境没有配置好。

命令docker-machine env default,注意default是docker的主机名称,可以使用docker-machine ls查看。

F:\java\Docker>docker-machine env default
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\zsl-pc\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM     @FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

F:\java\Docker>@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

注意上面是两个命令:

docker-machine env default
@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

上面的default都是Docker的主机名称。

测试Docker

通过上面几个步骤已经完成Docker在Windows8中的安装,现在使用命令docker run hello-world运行一个hello-world的测试容器:

F:\java\Docker>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
 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

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/engine/userguide/

只要出现上面的信息就表示Docker已经正常安装成功!

本文所属【知识林】:http://www.zslin.com/web/article/detail/2
文章点评共:0 条
点评内容: 提交点评