docker-machine是docker的管理工具用于在虚拟机上安装docker engine(docker engine就是常说的docker)和管理虚拟机。(docker-machine overview)
本文采用windows10安装docker-machine,使用windows10自带虚拟机hyper-v
windows10 64位 Build 10.0.16299(需要win8 以上Build版本>=15063, cmd窗口systeminfo查看OS版本)
内存>4g,BIOS启用虚拟化技术,开启windows features的Hyper-v功能。
重启电脑,本文F12进入,开启Virtualization Technology虚拟化技术,保存并退出。 ( 选择进入SETUP的快捷键不同品牌不相同)
启动后,win+s 搜索 windows features, 勾选Hyper-V, 保存退出。重启电脑
查看任务管理器,虚拟化已启用
参考:启用hyper-v
base=https://github.com/docker/machine/releases/download/v0.16.0 &&
mkdir -p "D:/docker/machine/bin" &&
curl -L $base/docker-machine-Windows-x86_64.exe > "D:/docker/machine/bin/docker-machine.exe" &&
chmod +x "D:/docker/machine/bin/docker-machine.exe"
等待下载完成,启动power shell,cd至安装目录,
PS D:\docker\machine\bin> .\docker-machine.exe -v
docker-machine.exe version 0.16.0, build 702c267f
参考:安装docker-machine
docker-machine创建虚拟机需要配置一个虚拟交换机。配置如下:
1. win+s 搜索打开Hyper-V管理器
2. 点击 虚拟交换机管理 配置虚拟交换机,选择新建虚拟网络交换机 -> 外部 -> 创建虚拟交换机
3. 填写交换机名称(随便起个名), 选择一个网卡(电脑一般有无线和有线网卡), 确定 退出
管理员身分运行power shell,运行命令:.\docker-machine.exe create -d hyperv --hyperv-virtual-switch "Virtual Switch(Main)" manager1, 创建hyperv类型虚拟机并指定交换机名称和虚拟机名称。
PS D:\docker\machine\bin> .\docker-machine.exe create -d hyperv --hyperv-virtual-switch "Virtual Switch(Main)" manager1
Running pre-create checks...
(manager1) Image cache directory does not exist, creating it at C:\Users\tom\.docker\machine\cache...
(manager1) No default Boot2Docker ISO found locally, downloading the latest release...
(manager1) Latest release for github.com/boot2docker/boot2docker is v18.09.6
(manager1) Downloading C:\Users\tom\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot
2docker/releases/download/v18.09.6/boot2docker.iso...
(manager1) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(manager1) Copying C:\Users\tom\.docker\machine\cache\boot2docker.iso to C:\Users\tom\.docker\machine\machines\manager1\boot2docker.iso...
(manager1) Creating SSH key...
(manager1) Creating VM...
(manager1) Using switch "Virtual Switch(Main)"
(manager1) Creating VHD
(manager1) Starting VM...
(manager1) Waiting for host to start...
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: D:\docker\machine\bin\docker-machine.exe env manager1
再使用上述命令创建两个worker,
.\docker-machine.exe create -d hyperv --hyperv-virtual-switch "Virtual Switch(Main)" worker1
.\docker-machine.exe create -d hyperv --hyperv-virtual-switch "Virtual Switch(Main)" worker2
其他参数,--help查看
$ docker-machine create --help
虚拟机创建成功,在Hyper-v管理器上也可以看到
参照:docker-machine(hyper-v)