入门:准备适用于容器的 WindowsGet started: Prep Windows for containers

本教程介绍如何执行以下操作:This tutorial describes how to:

先决条件Prerequisites

Windows ServerWindows Server

若要在 Windows Server 上运行容器,需要一台运行 Windows Server(半年频道)、Windows Server 2019 或 Windows Server 2016 的物理服务器或虚拟机。To run containers on Windows Server, you need a physical server or virtual machine running Windows Server (Semi-Annual Channel), Windows Server 2019, or Windows Server 2016.

若要进行测试,可以下载 Windows Server 2019 评估版Windows Server Insider Preview 的副本。For testing, you can download a copy of Windows Server 2019 Evaluation or a Windows Server Insider Preview.

Windows 10Windows 10

若要在 Windows 10 上运行容器,需要以下各项:To run containers on Windows 10, you need the following:

  • 一个运行 Windows 10 专业版或企业版(含周年更新(版本 1607)或更高版本)的物理计算机系统。One physical computer system running Windows 10 Professional or Enterprise with Anniversary Update (version 1607) or later.
  • Hyper-V 应已启用。Hyper-V should be enabled.

备注

从 Windows 10 的 2018 年 10 月更新版开始,我们不再允许用户在 Windows 10 企业版或专业版上以进程隔离模式运行 Windows 容器进行开发/测试。Starting with the Windows 10 October Update 2018, we no longer disallow users from running a Windows container in process-isolation mode on Windows 10 Enterprise or Professional for dev/test purposes. 有关详细信息,请参阅常见问题解答See the FAQ to learn more.

Windows Server 容器在 Windows 10 上默认使用 Hyper-V 隔离,为开发人员提供在生产中使用的相同内核版本和配置。Windows Server Containers use Hyper-V isolation by default on Windows 10 in order to provide developers with the same kernel version and configuration that will be used in production. 有关 Hyper-V 隔离的详细信息,请参阅文档的概念部分。Learn more about Hyper-V isolation in the Concepts area of our docs.

安装 DockerInstall Docker

第一步是安装 Docker,这是使用 Windows 容器所必需的。The first step is to install Docker, which is required for working with Windows containers. Docker 为容器提供标准的运行时环境,该环境具有通用的 API 和命令行接口 (CLI)。Docker provides a standard runtime environment for containers, with a common API and command-line interface (CLI).

如需更多配置详细信息,请参阅 Windows 上的 Docker 引擎For more configuration details, see Docker Engine on Windows.

若要在 Windows Server 上安装 Docker,可以使用由 Microsoft 发布的 OneGet 提供程序 PowerShell 模块(称为 DockerMicrosoftProvider)。To install Docker on Windows Server, you can use a OneGet provider PowerShell module published by Microsoft called the DockerMicrosoftProvider. 此提供程序启用 Windows 中的容器功能,并安装 Docker 引擎和客户端。This provider enables the containers feature in Windows and installs the Docker engine and client. 以下是操作方法:Here's how:

  1. 打开提升的 PowerShell 会话,从 PowerShell 库安装 Docker-Microsoft PackageManagement 提供程序。Open an elevated PowerShell session and install the Docker-Microsoft PackageManagement Provider from the PowerShell Gallery.

    Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
    

    如果系统提示安装 NuGet 提供程序,还请键入 Y 进行安装。If you're prompted to install the NuGet provider, type Y to install it as well.

  2. 使用 PackageManagement PowerShell 模块安装最新版本的 Docker。Use the PackageManagement PowerShell module to install the latest version of Docker.

    Install-Package -Name docker -ProviderName DockerMsftProvider
    

    PowerShell 询问是否信任包源“DockerDefault”时,键入 A 以继续进行安装。When PowerShell asks you whether to trust the package source 'DockerDefault', type A to continue the installation.

  3. 在安装完成后,请重启计算机。After the installation completes, restart the computer.

    Restart-Computer -Force
    

如果希望稍后更新 Docker,请执行以下操作:If you want to update Docker later:

  • 使用以下项检查安装的版本:Check the installed version using:
Get-Package -Name Docker -ProviderName DockerMsftProvider
  • 使用以下项查找当前版本:Find the current version using:
Find-Package -Name Docker -ProviderName DockerMsftProvider
  • 准备就绪后,使用以下项进行升级:When you're ready, upgrade using:
Install-Package -Name Docker -ProviderName DockerMsftProvider -Update -Force
  • 然后使用以下项:Then, followed with:
Start-Service Docker

后续步骤Next steps

正确配置环境后,可以单击链接,了解如何运行容器。Now that your environment has been configured correctly, follow the link to learn how to run a container.