在Windows10安装Docker遇到问题的解决方法

在 Windows 上安装Docker是一个相当简单和直接的过程,之前接触Docker是在 Centos 系统下,在 Windows 下并没有尝试过

我司的项目一直在用Docker,我在我司用的电脑也是 Windows10,其他人基本都是 Mac,入职的时候我是按照内部 Wiki建的环境,使用的VirtualBoxvagrant

不过现在有一个新的项目,所以还是尝试一下使用Docker,同时为了在自己笔记本上假期练习或者修改 Bug 方便点,就在自己的电脑上装起来Docker

开始说我的问题吧

1、家庭版安装 Docker for Windows

我的笔记本当初买的时候就家庭版,也没有太关注,看文档直接下载了Docker for Windows,结果安装就GG了,直接提示:

Installation failed:one pre-requisite is not full filled

Docker 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功能中关闭居然没生效,重启过的,安装Docker Toolbox倒是没有什么大问题

1)但是如果像我一样安装了Hyper-V,可能将无法正常使用,尝试启动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...

这个我的解决方式是直接把Hyepr-v禁用,管理员模式运行 CMD:

//To disable:
bcdedit /set hypervisorlaunchtype off

//To enable:
bcdedit /set hypervisorlaunchtype auto 

问题就解决了,当然还有另外一种方式

我们修改启动文件以允许它创建默认的 VM,我们要修改的文件位于C:\Program Files\Docker Toolbox\start.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 Files\Oracle\VirtualBox\VBoxManage.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:\tinderbox\win-5.2\src\VBox\Main\src-server\HostNetworkInterfaceImpl.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 Files\Oracle\VirtualBox\VBoxManage.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:\\Users\\username\\.docker\\machine\\machines\\default\\ca.pem": open C:\Users\username\.docker\machine\machines\default\ca.pem: The system cannot find the file specified.

这个问题是因为在安装Toolbox的时候有写入环境变量,这个证书的路径是配置在环境变量中的,卸载的时候环境变量还在

所以右键我的电脑–>属性–>高级系统设置–>环境变量–>用户变量,把那几个Docker的环境变量全部删掉

重新打开命令行窗口执行命令,就发现可以使用了

6 条评论

发表评论

*