在window server 2016下安装docker 创建镜
docker 基本操作可以看
https://www.jianshu.com/p/c69a2a3b4c7a
linux上安装可以看https://www.jianshu.com/p/dc38b80727e4
查看系统版本
开始---运行---输入winver

打开PowerShell

运行sconfig,选择6 回车

选择A更新所有

输入以下命令安装
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider
Restart-Computer -Force
如果系统提示你安装 NuGet 提供程序,请键入 Y 进行安装。
PowerShell 询问是否信任包源“DockerDefault”时,键入 A 以继续进行安装。

安装过程可能会报错
警告: Cannot verify the file SHA256. Deleting the file.
警告: C:\Users\AD[图片上传中...(image.png-a30232-1577693147705-0)]
MINI~1\AppData\Local\Temp\2\DockerMsftProvider\Docker-19-03-5.zip does not exist

解决方法:
定位到“C:\Users\ADMINI~1\AppData\Local\Temp\2\DockerMsftProvider”目录,打开DockerDefault_DockerSearchIndex.json文件,搜索“Docker-19-03-1.zip”,找到下载路径,手动下载

将下载好的文件,复制到“C:\Users\ADMINI~1\AppData\Local\Temp\2\DockerMsftProvider”目录

然后运行命令:
Find-Package -ProviderName DockerMsftProvider | Install-Package -Verbose

安装完成后重启计算机
Restart-Computer -Force
发布.net
如果没有dockerfile文件添加dockerfile文件

将发布后的代码上传到服务器

根据目录下的Dockerfile创建镜像:docker build -t dockerapitestimage . (注意,注意,注意后面有一个点“.”,这个点表示当前目录上下文)

到这一步发现错误
a Windows version 10.0.17134-based image is incompatible with a 10.0.14393 host
查阅了很多资料,最有用的就是如下这两个信息:
stackoverflow:https://stackoverflow.com/questions/54229367/dockers-image-and-host-are-incompatible
*windows 容器的兼容性:*****https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility****
意思是 基础镜像库(FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1903 )不支持在Windows Server 2016(10.0.14393) 服务器上运行。 但是支持在Win 10(10.为。17134)电脑上运行。**
在Win 10电脑上用Docker环境上开发一个程序,而不能在自家的服务器Window Server 2016上运行。
解决方法:
换个匹配的镜像
镜像查找
https://hub.docker.com/_/microsoft-dotnet-core-aspnet/
dockerfile文件修改后代码,用的是2.2的sdk,windows server2016
FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-sac2016 AS base
WORKDIR /app
EXPOSE 80
COPY . .
ENTRYPOINT ["dotnet", "webapi.dll"]
查看镜像
docker images

运行容器
docker run --name dockerapitestimage -d -p 5089:80 dockerapitestimage
