在windows上安装docker是一个相对简单且直接的过程。我之前主要在centos系统上使用docker,尚未在windows环境下尝试过。
我所在公司的项目一直使用Docker,而我工作的电脑是Windows10,其他同事大多使用Mac。入职时,我按照内部Wiki的指导,使用VirtualBox和vagrant搭建了环境。
现在有一个新项目,因此我决定尝试在Windows上使用Docker,同时为了在假期期间便于在笔记本上练习或修复bug,我也想在自己的电脑上安装Docker。
现在来讲讲我遇到的问题。
1、家庭版安装Docker for Windows我的笔记本当初购买时是家庭版,安装时没有特别注意,直接下载了Docker for Windows,结果安装失败,提示如下错误:
Installation failed:one pre-requisite is not full filledDocker for Windows requires Windows 10 Pro or Enterpriser version 14393,or Windows server 2016 RTM to run
原因是Docker支持在Mac、Windows、linux上安装,但在Windows10系统中,Docker for Windows目前只能在64位的Windows10专业版、企业版或教育版下安装。Win7/Win8/win10家庭版需要通过Docker Toolbox来安装,而我的电脑是家庭版的,尝试安装Docker for Windows导致失败。
2、在已安装Hyper-V的Windows上安装Docker Toolbox这是最棘手的问题,可能遇到多个难题。
Docker for Windows依赖Hyper-V,而Docker Toolbox使用VirtualBox。我之前已经安装了Hyper-V,这是因为Windows10家庭版没有Hyper-V功能,我通过之前文章中提到的方法添加了Hyper-V。
在Windows功能中关闭Hyper-V后,即使重启电脑,效果也不明显,安装Docker Toolbox时没有大问题。
1)但如果像我一样已经安装了Hyper-V,可能无法正常使用Docker Toolbox。尝试启动Docker QuickStart Terminal时,会出现以下错误:
Running pre-create checks...Error with pre-create check: "This computer is running Hyper-V. VirtualBox won't boot a 64bits VM when Hyper-V is activated. Either use Hyper-V as a driver, or disable the Hyper-V hypervisor. (To skip this check, use --virtualbox-no-vtx-check)"Looks like something went wrong in step ´Checking if machine default exists´... Press any key to continue...
我的解决方法是直接禁用Hyper-V,在管理员模式下运行CMD:
//禁用:bcdedit /set hypervisorlaunchtype off//启用:bcdedit /set hypervisorlaunchtype auto
这样问题就解决了,当然还有另一种方法。
我们可以通过修改启动文件来允许创建默认的VM。需要修改的文件位于C:Program FilesDocker Toolboxstart.sh,必须以管理员身份运行的编辑器中打开文件。
在编辑文件之前,可能需要保存原始文件的副本,以防万一。找到以下代码片段:
STEP="Checking if machine $VM exists"if [ $VM_EXISTS_CODE -eq 1 ]; then "${DOCKER_MACHINE}" rm -f "${VM}" &> /dev/null || : rm -rf ~/.docker/machine/machines/"${VM}" #set proxy variables if they exists if [ "${HTTP_PROXY}" ]; then PROXY_ENV="$PROXY_ENV --engine-env HTTP_PROXY=$HTTP_PROXY" fi if [ "${HTTPS_PROXY}" ]; then PROXY_ENV="$PROXY_ENV --engine-env HTTPS_PROXY=$HTTPS_PROXY" fi if [ "${NO_PROXY}" ]; then PROXY_ENV="$PROXY_ENV --engine-env NO_PROXY=$NO_PROXY" fi "${DOCKER_MACHINE}" create -d virtualbox $PROXY_ENV "${VM}"fi
在倒数第二行是创建虚拟机的地方:
"${DOCKER_MACHINE}" create -d virtualbox $PROXY_ENV "${VM}"
修改该行并添加–virtualbox-no-vtx-check。最终结果是:
"${DOCKER_MACHINE}" create -d virtualbox --virtualbox-no-vtx-check $PROXY_ENV "${VM}"
保存更改后,现在应该可以运行Docker QuickStart Terminal而不会出现任何问题。
2)Power up failed (vrc=VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT, rc=E_FAIL (0X80004005))
如果按照上一个问题的第二个方法解决,第二次启动时会报错:
Starting "default"...(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) Creating a new host-only adapter produced an error: C:Program FilesoracleVirtualBoxVBoxManage.exe hostonlyif create failed:(default) 0%...(default) Progress state: E_INVALIDARG(default) VBoxManage.exe: error: Failed to create the host-only adapter(default) VBoxManage.exe: error: Assertion failed: [!aInterfaceName.isEmpty()] at 'F: inderboxwin-5.2srcVBoxMainsrc-serverHostNetworkInterfaceImpl.cpp' (76) in long __cdecl HostNetworkInterface::init(class com::Bstr,class com::Bstr,class com::Guid,enum __MIDL___MIDL_itf_VirtualBox_0000_0000_0038).(default) VBoxManage.exe: error: Please contact the product vendor!(default) VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface(default) VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreate(struct HandlerArg *)" at line 94 of file VBoxManageHostonly.cpp(default)(default) This is a known VirtualBox bug. Let's try to recover anyway...(default) Found a new host-only adapter: "VirtualBox Host-Only Ethernet Adapter #5"(default) Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.(default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.Unable to start the VM: C:Program FilesOracleVirtualBoxVBoxManage.exe startvm default --type headless failed:VBoxManage.exe: error: Raw-mode is unavailable courtesy of Hyper-V. (VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT)VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole Details: 00:00:01.889052 Power up failed (vrc=VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT, rc=E_FAIL (0X80004005))
这个问题的解决方案是:关闭Hyper-V后,重启电脑即可正常运行。
然后使用以下命令:
docker-machine create –driver virtualbox node1
3、Docker for Windows使用命令报错家庭版无法直接安装Docker for Windows,因此我将电脑升级为专业版,然后进行安装。
这个问题出现在安装过Docker Toolbox又卸载后再安装Docker for Windows时,使用Docker命令时出现报错,提示找不到CA证书:
could not read CA certificate "C:Usersusername.dockermachinemachinesdefaultca.pem": open C:Usersusername.dockermachinemachinesdefaultca.pem: The system cannot find the file specified.
这是因为在安装Docker Toolbox时,环境变量中写入了一些路径,卸载时这些环境变量并未清除。
因此,右键我的电脑->属性->高级系统设置->环境变量->用户变量,将所有Docker相关的环境变量删除。
重新打开命令行窗口执行命令后,发现可以正常使用了。
沈唁志|一个PHPer的成长之路! 原创文章采用CC BY-NC-SA 4.0协议进行许可,转载请注明:转载自:在Windows10安装Docker遇到问题的解决方法