Windows 和容器Windows and containers

容器是一種跨內部部署和雲端中的不同環境封裝和執行 Windows 和 Linux 應用程式的技術。Containers are a technology for packaging and running Windows and Linux applications across diverse environments on-premises and in the cloud. 容器提供了輕量型、隔離的環境,讓應用程式更容易開發、部署和管理。Containers provide a lightweight, isolated environment that makes apps easier to develop, deploy, and manage. 容器可快速啟動和停止,使其適合需要快速適應變動需求的應用程式。Containers start and stop quickly, making them ideal for apps that need to rapidly adapt to changing demand. 容器的輕量本質也會使其成為可增加基礎結構密度和使用率的實用工具。The lightweight nature of containers also make them a useful tool for increasing the density and utilization of your infrastructure.

此圖形顯示容器在雲端或內部部署環境中執行的方式,並支援以幾乎任何語言撰寫的整合型應用程式或微服務。

Microsoft 容器生態系統The Microsoft container ecosystem

Microsoft 提供一些工具和平台,協助您在容器中開發和部署應用程式:Microsoft provides a number of tools and platforms to help you develop and deploy apps in containers:

容器的運作方式How containers work

容器是一個隔離且輕量型的定址接收器,用於在主機作業系統上執行應用程式。A container is an isolated, lightweight silo for running an application on the host operating system. 容器是以主機作業系統的核心 (可視為作業系統的「地下管線」) 為基礎,如下圖所示。Containers build on top of the host operating system's kernel (which can be thought of as the buried plumbing of the operating system), as shown in this diagram.

顯示如何在核心上執行容器的架構圖

當容器共用主機作業系統的核心時,該容器不會取得其自由的存取權。While a container shares the host operating system's kernel, the container doesn't get unfettered access to it. 然而,容器會取得隔離的 (在某些情況下為虛擬化) 的系統檢視。Instead, the container gets an isolated–and in some cases virtualized–view of the system. 例如,容器可以存取虛擬化版本的檔案系統和登錄,但任何變更都只會影響容器並在容器停止時予以捨棄。For example, a container can access a virtualized version of the file system and registry, but any changes affect only the container and are discarded when it stops. 若要儲存資料,容器可以掛接持續性儲存體,例如 Azure 磁碟或檔案共用 (包括 Azure 檔案)。To save data, the container can mount persistent storage such as an Azure Disk or a file share (including Azure Files).

容器是以核心為基礎,但核心並未提供應用程式執行時需要的所有 API 和服務,這些大多數是由以使用者模式在核心之上執行的系統檔案 (程式庫) 所提供。A container builds on top of the kernel, but the kernel doesn't provide all of the APIs and services an app needs to run–most of these are provided by system files (libraries) that run above the kernel in user mode. 由於容器與主機的使用者模式環境隔離,因此容器需要自己的使用者模式系統檔案複本,而這些檔案會封裝成所謂的基底映像。Because a container is isolated from the host's user mode environment, the container needs its own copy of these user mode system files, which are packaged into something known as a base image. 基底映像可作為建立容器的基礎層,並為其提供核心所未提供的作業系統服務。The base image serves as the foundational layer upon which your container is built, providing it with operating system services not provided by the kernel. 但我們稍後會詳細討論容器映像。But we'll talk more about container images later.

容器與虛擬機器Containers vs. virtual machines

與容器相比,虛擬機器 (VM) 會執行完整的作業系統 (包括它自己的核心),如下圖所示。In contrast to a container, a virtual machine (VMs) runs a complete operating system–including its own kernel–as shown in this diagram.

顯示 VM 如何在主機作業系統旁執行完整作業系統的架構圖

容器和虛擬機器都有其用途:事實上,許多容器部署都會使用虛擬機器作為主機作業系統,而不是直接在硬體上執行,尤其是在雲端中執行容器時。Containers and virtual machines each have their uses–in fact, many deployments of containers use virtual machines as the host operating system rather than running directly on the hardware, especially when running containers in the cloud.

如需這些互補技術的相似性與差異詳細資訊,請參閱容器與虛擬機器For more details on the similarities and differences of these complementary technologies, see Containers vs. virtual machines.

容器映像Container images

所有容器都是從容器映像建立而來。All containers are created from container images. 容器映像是一套組織成層級堆疊的檔案組合,其位於本機電腦或遠端容器登錄中。Container images are a bundle of files organized into a stack of layers that reside on your local machine or in a remote container registry. 容器映像包含支援您應用程式所需的使用者模式作業系統檔案、您的應用程式、您應用程式的任何執行階段或相依性,以及您的應用程式正常執行時所需的任何其他組態檔。The container image consists of the user mode operating system files needed to support your app, your app, any runtimes or dependencies of your app, and any other miscellaneous configuration file your app needs to run properly.

Microsoft 提供數個映像 (稱為基底映像),您可將其作為建立自有容器映像的起點:Microsoft offers several images (called base images) that you can use as a starting point to build your own container image:

  • Windows - 包含一組完整的 Windows API 和系統服務 (沒有伺服器角色)。Windows - contains the full set of Windows APIs and system services (minus server roles).
  • Windows Server Core - 較小的映像,其包含 Windows Server API 的子集 – 也就是完整的 .NET 架構。Windows Server Core - a smaller image that contains a subset of the Windows Server APIs–namely the full .NET framework. 它也包含大部分的伺服器角色 (雖然很少),但不包含傳真伺服器。It also includes most server roles, though sadly to few, not Fax Server.
  • Nano Server - 最小的 Windows Server 映像,支援 .NET Core API 和某些伺服器角色。Nano Server - the smallest Windows Server image, with support for the .NET Core APIs and some server roles.
  • Windows 10 IoT Core - 硬體製造商針對執行 ARM 或 x86/x64 處理器的小型物聯網 (IoT) 裝置所使用的 Windows 版本。Windows 10 IoT Core - a version of Windows used by hardware manufacturers for small Internet of Things devices that run ARM or x86/x64 processors.

如先前所述,容器映像是由一系列的層級所組成。As mentioned earlier, container images are composed of a series of layers. 每一層都包含一組檔案,若覆疊在一起,即代表您的容器映像。Each layer contains a set of files that, when overlaid together, represent your container image. 由於容器的分層本質,您不需要一律以基底映像為目標來建立 Windows 容器。Because of the layered nature of containers, you don't have to always target a base image to build a Windows container. 然而,您可以將目標設為已有您想要架構的另一個映像。Instead, you could target another image that already carries the framework you want. 例如,.NET 小組會發佈帶有 .NET 核心執行階段的 .NET 核心映像For example, the .NET team publishes a .NET core image that carries the .NET core runtime. 這可讓使用者不需要重複進行安裝 .NET 核心的程序,而是可以重複使用此容器映像的層級。It saves users from needing to duplicate the process of installing .NET core–instead they can reuse the layers of this container image. .NET 核心映像本身是根據 Nano Server 所建立。The .NET core image itself is built based upon Nano Server.

如需詳細資訊,請參閱容器基底映像For more details, see Container Base Images.

容器使用者Container users

開發人員的容器Containers for developers

容器可協助開發人員更快速地建置及提供更高品質的應用程式。Containers help developers build and ship higher-quality apps, faster. 使用容器,開發人員可以建立在幾秒內部署的容器映像 (在不同的環境中都相同)。With containers, developers can create a container image that deploys in seconds, identically across environments. 容器的作用是跨小組共用程式碼及啟動開發環境的簡單機制,但不會影響主機檔案系統。Containers act as an easy mechanism to share code across teams and to bootstrap a development environment without impacting your host filesystem.

容器具有可攜性和廣泛性,可執行以任何語言撰寫的應用程式,而且與任何執行 Windows 10、1607 版或更新版本或 Windows Server 2016 或更新版本的電腦相容。Containers are portable and versatile, can run apps written in any language, and they're compatible with any machine running Windows 10, version 1607 or later, or Windows Server 2016 or later. 開發人員可以在其膝上型或桌上型電腦本機建立及測試容器,然後將相同的容器映像部署到其公司的私人雲端、公用雲端或服務提供者。Developers can create and test a container locally on their laptop or desktop, and then deploy that same container image to their company's private cloud, public cloud, or service provider. 容器既有的靈活性可支援大規模、虛擬化雲端環境中的新型應用程式開發模式。The natural agility of containers supports modern app development patterns in large-scale, virtualized cloud environments.

IT 專業人員的容器Containers for IT professionals

容器可協助系統管理員建立更容易更新和維護並可充分利用硬體資源的基礎結構。Containers help admins create infrastructure that's easier to update and maintain, and that more fully utilizes hardware resources. IT 專業人員可以使用容器為其開發、品管及生產小組提供標準化的環境。IT professionals can use containers to provide standardized environments for their development, QA, and production teams. 藉由使用容器,系統管理員可抽離作業系統安裝與基礎結構的差異。By using containers, systems administrators abstract away differences in operating system installations and the underlying infrastructure.

容器協調流程Container orchestration

在設定容器型環境時,協調器是基礎結構的重要部分。Orchestrators are a critical piece of infrastructure when setting up a container-based environment. 雖然您可以使用 Docker 和 Windows 手動管理一些容器,但應用程式通常會使用五個、十個或甚至數百個容器 (協調器的來源)。While you can manage a few containers manually using Docker and Windows, apps often make use of five, ten, or even hundreds of containers, which is where orchestrators come in.

為了協助大規模管理生產環境中的容器,於是建立了容器協調器。Container orchestrators were built to help manage containers at scale and in production. 協調器可提供下列功能:Orchestrators provide functionality for:

  • 大規模部署Deploying at scale
  • 工作負載排程Workload scheduling
  • 健全狀況監視Health monitoring
  • 當節點失敗時容錯移轉Failing over when a node fails
  • 擴大或縮小規模Scaling up or down
  • 網路功能Networking
  • 服務探索Service discovery
  • 協調應用程式升級Coordinating app upgrades
  • 叢集節點親和性Cluster node affinity

有許多不同的協調器可供您用於 Windows 容器,以下是 Microsoft 提供的選項:There are many different orchestrators that you can use with Windows containers; here are the options Microsoft provides:

在 Windows 上試用容器Try containers on Windows

若要開始在 Windows Server 或 Windows 10 上使用容器,請參閱下列各項:To get started with containers on Windows Server or Windows 10, see the following:

若要協助判斷您的案例適合那些 Azure 服務,請參閱 Azure 容器服務選擇要用於裝載應用程式的 Azure 服務For help deciding which Azure services are right for your scenario, see Azure container services and Choosing what Azure services to use to host your application.