在 Windows Server 2019 上安装 dapr ,安装成功后有一段提示文字
Ensure that Docker Desktop is set to Linux containers mode when you run Dapr in self hosted mode.
开始时没注意到这个提示,然后安装 docker engine
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider
接着运行 dapr init ,报下面的错误
docker: no matching manifest for windows/amd64 10.0.17763 in the manifest list entries.
查找资料后得知 docker engine 默认是 Windows container 模式,解决上面的错误需要切换到 Linux container 模式,这时才注意到安装 dapr 时的提示。
通过 docker desktop 切换到 Linux container 模式,但 docker engine 总是启动失败,报错如下:
The Virtual Machine Management Service failed to start the virtual machine 'DockerDesktopVM' because one of the Hyper-V components is not running
折腾一阵,没有解决,后来通过 Run Docker Containers on Windows Server 2019 知道原来需要安装 preview 版 Docker EE。
通过下面的一系列 powershell 命令安装 preview 版 Docker EE 之后,支持 Linux container 模式终于成功启动。
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Uninstall-Package -Name docker -ProviderName DockerMSFTProvider
Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
Restart-Computer -Force
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
Restart-Service docker
但是运行 dapr init 出现新的错误
docker: failed to register layer: failed to start service utility VM (applydiff 88e57cc977280a42ef93829fad29a6ffbe1be1320278764f77575546056c1800): container 88e57cc977280a42ef93829fad29a6ffbe1be1320278764f77575546056c1800_svm encountered an error during CreateContainer: failure in a Windows system call: The virtual machine could not be started because a required feature is not installed. (0xc0370102) extra info: {"SystemType":"container","Name":"88e57cc977280a42ef93829fad29a6ffbe1be1320278764f77575546056c1800_svm","Layers":null,"HvPartition":true,"HvRuntime":{"ImagePath":"C:\Program Files\Linux Containers","LinuxInitrdFile":"initrd.img","LinuxKernelFile":"bootx64.efi"},"ContainerType":"linux","TerminateOnLastHandleClosed":true}.
运行 ubuntu 容器也是同样的错误
docker run -it --rm ubuntu /bin/bash
又折腾一阵,通过 Azure VM Docker CreateContainer Error (0xc0370102) 知道原来需要云服务器支持 Nested Virtualization,看来当前使用的百度云服务器不支持。
换到阿里云试试,阿里云提供了专门的“Windows Server 2019 with Container 数据中心版”镜像,用这个镜像也未能成功运行 Linux container。