Docker windows 版本容器兼容性

Docker windows version container compatibility

有一个问题没有出现在论坛中,有什么值得讨论的,恕我直言: 为什么无法在较旧的主机系统上拉取或构建 windows docker 图像(即 nanoserver 2019)?在官方网站上,它与 运行 不兼容,是的: Version compatibility

但是,正如我所说,"to run"。我不需要 运行 较新的 windows 旧主机系统上的容器映像,我只想拉取并构建它,稍后将其分发到兼容系统。

所以,有没有办法处理这个不应该的问题?

你错过了一件重要的事情:

即使只做 docker build,它也会使用容器,它使用容器来构建而不是直接在你的 host 机器上。接下来是docker build:

时的过程
  1. Docker 将从您在 Docker 文件中使用 FROM.

    提到的基础映像创建一个临时构建容器
  2. 运行 以上临时构建容器中 Docker 文件的所有说明。

  3. 将临时构建容器另存为图像。

因此,正如您所说,您已经从 microsoft 看到了容器的 Version compatibility,所以现在我想您也可以理解为什么构建也需要这个,只是因为它还会创建一个container(只是这个临时容器会在构建后被移除)。

更新:

整个故事是:

YES,在 linux 中,旧的 host os 到 build/run 新的 os image/container 没问题,因为host和container只是共享同一个kernel,rootfs由container自己提供。

但是,你说的是 windows,从 windows official,我们可以看到下一个:

Windows Server 2016 and Windows 10 Anniversary Update (both version 14393) were the first Windows releases that could build and run Windows Server containers. Containers built using these versions can run on newer releases such as Windows Server version 1709, but there are a few things you need to know before you start.

As we've been improving the Windows container features, we've had to make some changes that can affect compatibility. Older containers will run the same on newer hosts with Hyper-V isolation, and will use the same (older) kernel version. However, if you want to run a container based on a newer Windows build, it can only run on the newer host build.

以上是旧windowsos无法运行新windows容器的原因。

另外,我想说的是docker builddocker run是同一个道理:

docker run $theImageName 需要基于图像 theImageName 启动容器,正如 microsoft 所说,新的 os 容器必须使用新功能内核,因此新容器不能使用旧的 windows host。请记住,container 和 host 将共享同一个内核。

然后,docker build -t xxx .会找到Dockerfile里面有FROM $baseImageName,然后根据镜像$baseImageName启动一个容器,这个容器是一个临时容器。 Dockerfile 中的所有指令都将在此临时容器中执行,而不是在 dockerhost 中执行。最后,这个临时构建容器将被删除,所以你没有看到这个临时容器。

因此,如您所见,docker rundocker build 都将启动需要利用新的 windows host 功能的容器,无法使用旧 windows' 内核。这是 microsoft 的限制,如果你已经了解 windows 上 docker run 的限制,原因与 windows 上的 docker build 相同。