[Docker for Windows] ASP.NET Core 試玩
環境
- Docker for Windows
- image:aspnetcore (Linux base)
Step by Step
1.建立.netcore web application,在Contoller撰寫資料庫連線
View,顯示連線狀態
2.發行程式,使用File System
3.下載image
docker pull microsoft/aspnetcore4.在bin目錄下,新增Dockerfile
Dockerfile 內容
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM microsoft/aspnetcore | |
WORKDIR /app | |
## 將Release目錄copy到Container的app目錄 | |
ADD Release/ /app | |
ENTRYPOINT ["dotnet", "mynetcoreLab.dll"] |
5.建置Image
docker build -t mynetcoreapp .ps:紅字為安全性警告訊息,謎.....請忽略..。
6.執行Container
docker run -d -p 8001:80 --add-host db-ap1:192.168.1.101 --name mynetcore mynetcoreappps:add-host 為新增一筆record在etc/hosts內,讓此container可以連線到公司內的其他主機,本例主要為連線到公司內的資料庫。
7.測試程式
瀏覽器執行 http://localhost:8001/conn/open參考來源
http://kevintsengtw.blogspot.tw/2016/11/docker-for-windows-aspnet-core-part1.htmlhttps://docs.docker.com/engine/reference/run/#/managing-etchosts