在 Docker 中使用 PowerShellUsing PowerShell in Docker

我们发布了预安装 PowerShell 的 Docker 映像。We publish Docker images with PowerShell preinstalled. 本文介绍如何开始在 Docker 容器中使用 PowerShell。This article shows you how to get started using PowerShell in the Docker container.

查找可用映像Finding available images

已发布的映像需要 Docker 17.05 或更高版本。The released images require Docker 17.05 or newer. 还应在没有 sudo 或本地管理权限的情况下能够运行 Docker。It is also expected that you are able to run Docker without sudo or local administrative rights. 请按照 Docker 的官方说明正确安装 dockerPlease follow Docker's official instructions to install docker correctly.

发布容器派生自正式分发映像(如 centos:7),然后安装依赖项,最后安装 PowerShell 包。The release containers derive from the official distribution image, such as centos:7, then install dependencies, and finally install the PowerShell package.

这些容器位于 hub.docker.com/r/microsoft/powershellThese containers live at hub.docker.com/r/microsoft/powershell.

有关这些 Docker 映像的详细信息,请访问 GitHub 上的 PowerShell-Docker 存储库。For more information about these Docker images, visit the PowerShell-Docker repository on GitHub.

在容器中使用 PowerShellUsing PowerShell in a container

以下步骤显示了下载映像和启动交互式 PowerShell 会话所需的 Docker 命令。The following steps show the Docker commands required to download the image and start an interactive PowerShell session.

docker run -it mcr.microsoft.com/powershell

在不再需要映像时将其删除Remove the image when no longer needed

以下命令用于在不再需要 Docker 映像时将其删除。The following command is used to delete the Docker image when you no longer need it.

docker rmi mcr.microsoft.com/powershell

PowerShell 根据 MIT 许可获得授权。PowerShell is licensed under the MIT license.

Windows Docker 文件和映像许可证Windows Docker File and Image Licenses

通过请求和使用 Windows 容器的容器 OS 映像,你可以确认、了解并同意 Docker 中心提供的补充许可条款:By requesting and using the Container OS Image for Windows containers, you acknowledge, understand, and consent to the Supplemental License Terms available on Docker hub:

遥测Telemetry

默认情况下,PowerShell 会收集没有个人身份信息的有限遥测,以帮助开发 PowerShell 的未来版本。By default, PowerShell collects limited telemetry without personally identifiable information to help aid development of future versions of PowerShell. 若选择不要发送遥测,请在从安装位置启动 PowerShell 之前,创建名为 POWERSHELL_TELEMETRY_OPTOUT 且设置为 1 值的环境变量。To opt-out of sending telemetry, create an environment variable called POWERSHELL_TELEMETRY_OPTOUT set to a value of 1 before starting PowerShell from the installed location. 我们收集的遥测位于 Microsoft 隐私声明中。The telemetry we collect falls under the Microsoft Privacy Statement.