若要在 Windows Server 上安装 Docker,可以使用由 Microsoft 发布的 OneGet 提供程序 PowerShell 模块(称为 DockerMicrosoftProvider)。 此提供程序启用 Windows 中的容器功能,并安装 Docker 引擎和客户端。 以下是操作方法:
# Set the TLS version used by the PowerShell client to TLS 1.2. [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
如果看到错误消息“no matching manifest for linux/amd64 in the manifest list entries”,那说明 Docker 用的是Linux 容器。 注意:mcr.microsoft.com上的镜像在国内访问挺慢的,你可以先把镜像pull到阿里云,然后再在你电脑上拉取。 我们跑一个简单容器(执行cmd)
1
docker run -it mcr.microsoft.com/windows/nanoserver:ltsc2022-amd64 cmd.exe
# Build results [Dd]ebug/ [Rr]elease/ x64/ [Bb]in/ [Oo]bj/ # build folder is nowadays used for build scripts and should not be ignored #build/
# NuGet Packages *.nupkg # The packages folder can be ignored because of Package Restore **/packages/* # except build/, which is used as an MSBuild target. !**/packages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/packages/repositories.config
# MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.*
好了,现在执行docker build -t fuck_image .,构建镜像成功后,可以看到
1 2 3
PS C:\Users\Administrator> docker images REPOSITORY TAG IMAGE ID CREATED SIZE fuck_image latest a8b482b53388 5 hours ago 392MB
我们跑个容器docker run -d --name fuck_asp fuck_image,查看容器日志docker logs fuck_asp,发现它的http端口是80
1 2 3 4 5 6 7 8
info: Microsoft.Hosting.Lifetime[14] Now listening on: http://[::]:80 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production info: Microsoft.Hosting.Lifetime[0] Content root path: C:\app\