打破单一平台桎梏,Docker for Windows Desktop 18.02 尝鲜测评!

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dt763C/article/details/79409664

640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1

出品丨Docker公司(ID:docker-cn)

编译丨小东

每周一、三、五晚6点10分  与您不见不散


说在前面


Docker for Windows Desktop 18.02 新版本中最大的亮点之一就是拥有自动化的 Kubernetes 集群选项,它可以让您在 Windows 桌面系统上使用 Linux 容器来为您所喜欢的 Kubernetes 工具提供原生的支持。这是一件了不起的事!您可以尝试点击系统中的鲸鱼图标将 Docker for Windows Desktop 设置为 Linux 容器模式,然后通过“设置”菜单来启用对 Kubernetes 的支持。如果您使用的是最新的 Windows 10 Insider 版本构建的话,那么请注意 Windows 平台在 Docker for Windows Desktop 中会对 Linux 容器产生一定的影响。


当然这并不是本文的全部内容。我还会为大家介绍微软公司的 Linux containers on Windows(LCOW) 项目的进一步发展情况。Docker for Windows 18.02 现在可以通过 LCOW 使用单个 Docker 守护进程来支持 Linux 和 Windows 容器的并存运行。


更多关于 LCOW 的发展详情



640?wx_fmt=png

如何获取


Docker for Windows Desktop 18.02 是一个尝鲜的发行版本(Edge channel release)。如果您已经将 Docker for Windows Desktop 的副本设置为尝鲜(Edge)或夜间(Nightly)模式,那么您将会自动进行更新。稳定版本(Stable channel)的用户需要先切换到尝鲜或夜间模式才能进行更新。


注意:LCOW 需要 Hyper-V 隔离技术,因此 Windows 10 必须在裸机或支持嵌套虚拟化的平台(例如 Hyper-V 或 Azure Dv3 和 Ev3 实例)上运行。您的体验可能会因使用不同的虚拟化平台而产生差异。

640?wx_fmt=png


尝鲜测评


以前版本的 Docker for Windows Desktop 包含了以下三种操作模式:

 

  • Windows容器 —— 通过原生的 Windows 支持运行;

  • Linux容器 ——通过托管的Hyper-V Linux VM运行;

  • Linux containers on Windows (LCOW)

 

从18.02版本开始,将不再有单独的 LCOW 模式了,在Windows模式下,LCOW 现在用于 Windows 和 Linux 容器的并存运行。现有的 Linux 模式将被保留。你可以通过系统中的蓝鲸图标来切换模式。

 

640?wx_fmt=png


LCOW引入了一个基本概念,即单个 Docker 引擎能够为多个操作系统运行镜像。执行第一次下载镜像的操作时,需要一个指令来完成镜像和主机操作系统之间的匹配。在这个版本中,该指令是“--platform”标签。


640?wx_fmt=png


默认的主机操作系统是 Windows ,所以在不指定“--platform”标签的情况下运行Linux容器将提示有误:


docker run --rm busybox echo hello

 

Unable to find image 'busybox:latest' locally

latest: Pulling from library/busybox

docker.exe: no matching manifest for windows/amd64 in the manifest list entries.

See 'docker.exe run --help'.


添加“--platform linux”标签就可以成功的下载和运行容器了。


docker run --rm --platform linux busybox echo hello

 

Unable to find image 'busybox:latest' locally

latest: Pulling from library/busybox

57310166fe88: Pull complete

Digest: sha256:1669a6aa7350e1cdd28f972ddad5aceba2912f589f19a090ac75b7083da748db

Status: Downloaded newer image for busybox:latest

hello


一旦用指定的操作系统下载过镜像,那么就不再需要“--platform”标签了。


docker run --rm busybox echo hello

hello 


现在让我们来尝试使 Linux 和 Windows 容器并存运行:


docker run --rm microsoft/nanoserver:1709 cmd

 

Unable to find image 'microsoft/nanoserver:1709' locally

1709: Pulling from microsoft/nanoserver

407ada6e90de: Pull complete

711a33cda32c: Pull complete

Digest: sha256:c633d0187bcb73948ac51c8d84f19948b4151dc71274fced7ce204bbe403f33d

Status: Downloaded newer image for microsoft/nanoserver:1709

Microsoft Windows [Version 10.0.16299.192]

(c) 2017 Microsoft Corporation. All rights reserved.

 

C:\>


镜像列表同时包括了 Linux 和 Windows 镜像:


docker image ls

 

REPOSITORY              TAG      IMAGE ID      CREATED        SIZE

busybox                 latest   5b0d59026729  13 days ago    3.41MB

microsoft/nanoserver    1709     c4f1aa3885f1  4 weeks ago    303MB


将默认的主机操作系统更改为Linux:


[Environment]::SetEnvironmentVariable("LCOW_API_PLATFORM_IF_OMITTED", "linux", "Machine")

Restart-Service Docker

640?wx_fmt=png


“hello-world”和

清单列表镜像


眼尖的读者可能已经注意到了,上面的示例并没有使用普遍的“hello-world”镜像。这是为了展示LCOW和“--platform”标签如何与您将遇到的大多数镜像配合使用。但是一些镜像(比如在镜像仓库中的镜像)是使用清单列表进行构建的。清单列表是由 Docker 船长 Phil Estes 贡献的,它允许镜像作者指定用于不同架构、操作系统和操作系统版本的摘要。

 

清单列表详情请参考文章:



当指定的镜像具有清单列表时,Docker引擎会根据运行的主机操作系统自动选择要使用的清单条目。当清单列表与LCOW结合在一起时,您就可以通过“--platform windows”或“--platform linux”来引用单个镜像了。请注意,只有清单列表的单个镜像可以在给定的 Docker 引擎上进行下载。


“hello-world”的清单包含了 Windows 和 Linux 的条目(还有一些其他条目,为了简洁起见,省略了完整列表)。


 {

  "schemaVersion": 2,

  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",

  "manifests": [

    {

      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",

      "size": 524,

      "digest": "sha256:8072a54ebb3bc136150e2f2860f00a7bf45f13eeb917cca2430fcd0054c8e51b",

      "platform": {

        "architecture": "amd64",

        "os": "linux"

      }

   

    },

    {

      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",

      "size": 525,

      "digest": "sha256:f839819df2d0d86fad4f53641de64f6e90ae3b77d6ca28011c77ad34aa7afd92",

      "platform": {

        "architecture": "s390x",

        "os": "linux"

      }

    },

    {

      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",

      "size": 1358,

      "digest": "sha256:65b067b5940d834f7534027d90e47c634c4ab0c9d51d9a4a363166bb40787c15",

      "platform": {

        "architecture": "amd64",

        "os": "windows",

        "os.version": "10.0.14393.2007"

      }

    },

    {

      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",

      "size": 1356,

      "digest": "sha256:0583adf9c3d3c52a05a131ad1a868c9e61f550e83444f868d66bd83e1125bdc3",

      "platform": {

        "architecture": "amd64",

        "os": "windows",

        "os.version": "10.0.16299.192"

      }

    }

  ]

}

640?wx_fmt=png


Windows 镜像的兼容性


Windows 对于在 Windows 版本上创建和运行容器有着特定的要求。更多相关细节,请参阅微软公司关于容器版本兼容性的文档。如果您正在运行 Windows 10 Insider 版本,那么一定要确认哪些镜像可以与您的 Windows 版本兼容。微软公司在 Docker Hub 上提供了 Windows Insider 版本的基础镜像,如 microsoft / nanoserver-insider。


请注意,清单列表还允许作者创建可在不同 Windows 版本上运行的镜像,而不需要用户维护和指定明确的标签。“hello-world”清单中的两个Windows条目就是一个例子: Windows 10 1607(10.0.14393) 和 Windows 10 Fall Creators Update(10.0.16299) 。

640?wx_fmt=png


点击下列标题,阅读更多干货



如果本文对你有帮助,欢迎分享到朋友圈!获取更多Docker实用技巧,扫描下图二维码!

  640?wx_fmt=png

猜你喜欢

转载自blog.csdn.net/dt763C/article/details/79409664