網上不少文章都是在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了。
參考: