You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows Server 2022的Docker中同时运行Linux和Windows容器?

在Windows Server 2022的Docker中同时运行Linux和Windows容器

由于LCOW(Linux Containers on Windows)已被官方彻底弃用,包括实验模式支持也已取消,目前有两种稳定可行的替代方案:

方案1:通过WSL 2集成(官方推荐)

该方案利用Windows Subsystem for Linux 2作为Linux容器的运行后端,同时保留原生Windows容器支持,两者可并行运行。

  1. 启用WSL并安装Linux发行版
    在PowerShell中执行以下命令启用WSL功能:

    Install-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux
    

    重启服务器后,通过Microsoft Store或手动下载安装任意Linux发行版(如Ubuntu)。

  2. 配置Docker Engine使用WSL集成
    编辑Docker的配置文件C:\ProgramData\Docker\config\daemon.json,添加WSL集成配置(替换<你的WSL发行版名称>为实际名称,如Ubuntu):

    {
      "wslIntegration": {
        "<你的WSL发行版名称>": true
      },
      "features": {
        "buildkit": true
      }
    }
    

    重启Docker服务使配置生效:

    Restart-Service Docker
    
  3. 运行容器

    • 直接运行Windows容器:docker run mcr.microsoft.com/windows/servercore:ltsc2022
    • 直接运行Linux容器:docker run ubuntu:latest
      Docker会自动将Linux容器调度到WSL 2环境中,Windows容器则使用原生Windows容器后端。

方案2:使用Docker Context切换(无WSL场景备选)

如果无法使用WSL,可以通过Docker Context在Windows容器后端和远程Linux Docker主机之间切换,实现分别运行两种容器。

  1. 创建Windows容器上下文
    默认Docker上下文通常已指向Windows容器后端,若需显式创建:

    docker context create windows-local --docker host=npipe:////./pipe/docker_engine
    
  2. 创建Linux容器上下文
    假设你有一个运行Docker Engine的远程Linux主机,通过SSH连接创建上下文:

    docker context create linux-remote --docker host=ssh://<Linux主机用户名>@<Linux主机IP>
    
  3. 切换上下文运行容器

    • 切换到Windows上下文运行Windows容器:
      docker context use windows-local
      docker run mcr.microsoft.com/windows/servercore:ltsc2022
      
    • 切换到Linux上下文运行Linux容器:
      docker context use linux-remote
      docker run ubuntu:latest
      

关键注意事项

  • WSL 2集成方案无需切换上下文,两种容器可同时运行,是当前最便捷稳定的方式
  • 使用Context切换时,确保远程Linux主机的Docker Engine已正确配置,且SSH访问权限正常
  • Windows Server 2022上的Docker Engine需更新到较新版本,以支持WSL 2集成功能

内容的提问来源于stack exchange,提问作者Martin P.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 14:20:36