在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遇到問題的解決方法