网上不少文章都是在win10下,用Docker for windows工具进行Docker的安装部署的。用知道windows server 2016已经原生支持Docker了,其windows Container已经和Linux下的内核技术是一致的了,何况最重要的缘由就是Docker容器的部署确定是在Windows server 上面的。因此何不尝个鲜,直接用windows server 2016上装个visual studio 2017来进行开发呢。html
1、Windows Server 2016安装Dockergit
在windows server 2016上面安装Docker十分的简单,不须要像win10同样,装个Dokcer for windows工具,也不须要开启Hyper-V建个Linux虚拟机了。直接在Shell命令下面运行以下命令:github
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force Install-Package -Name docker -ProviderName DockerMsftProvider Restart-Computer -Force
能够参考 Windows Containers on Windows Serverdocker
重启完电脑,运行docker version会弹出以下界面,说明Docker已经安装完成windows
2、在ASP.NET Web Application项目上启用Docker的支持(注意不是.net core应用)app
使用Visual Studio 2017新建一个ASP.NET Web Application项目ide
在模板上随便选一个,这里不像.net core程序会有直接的Enable Docker Support的选项工具
不要紧,咱们能够直接在项目右键vs2017-》Add-》Docker Supportpost
就会多出以下文件visual-studio
基本上都是docker-compose和Dockerfile构建Docker容器用的。
3、启用Docker调试
若是这时按F5进行选择Docker进行调试,会出错,主要是docker-compose命令未找到。在Docker官网上找到了以下的说法:
Docker for Mac, Docker for Windows, and Docker Toolbox include Docker Compose, so most Mac and Windows users do not need to install Docker Compose separately.
If you are running the Docker daemon and client directly on Microsoft Windows Server 2016 (with Docker EE for Windows Server 2016), you do need to install Docker Compose.
To do this, start an “elevated” PowerShell (run it as administrator). Search for PowerShell, right-click, and choose Run as administrator. When asked if you want to allow this app to make changes to your device, click Yes.
Run the following command to download Docker Compose, replacing
$dockerComposeVersion
with the specific version of Compose you want to use:Invoke-WebRequest "https://github.com/docker/compose/releases/download/$dockerComposeVersion/docker-compose-Windows-x86_64.exe" -UseBasicParsing
-OutFile $Env:ProgramFiles\docker\docker-compose.exeFor example, to download Compose version 1.12.0, the command is:
none Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.12.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\docker\docker-compose.exe
Now, run the executable to install Compose.
参考: Install Docker Compose,咱们先找一下docker-compose的最新版本https://github.com/docker/compose/releases,发现是1.13.0,那么那句话能够直接改成
Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.13.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\docker\docker-compose.exe
满心期待的去运行F5,结果仍是报错:
ERROR: client version 1.22 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
查了一下,原来若是你使用Docker 1.13以上版本,须要将docker-compose.yml
中的version: '2'
修改成version: '2.1'
也就是这里的version
真的是一波三折,总算是没问题了,编译也能经过了。但是当调试F5的时候,却恰恰又出现远程调试错误。。。
这个时候,运行docker ps的命令,能够看到咱们的容器已经启动了
咱们查看一下容器IP
docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" $CONTAINER_ID
而后直接在游览器中访问,已经能够看到网站在运行了。
这个真的是蛮坑的地方,网上也没有相关资料,却是在stackoverflow发现相关问题:Running Visual Studio Remote Debugger in Windows Container (Docker managed),可是没什么用。最后想了半天,原来是server版的限制比较高,必须在防火墙中开发端口,或者直接关掉防火墙,就OK了。
参考: