eShopOnContainers 知多少[2]:Run起來

環(huán)境準備

  1. Win10(開啟Hyper-V)
  2. .NET Core SDK
  3. Docker for Windows
  4. VS2017 or VS Code
  5. Git
  6. SQL Server Management Studio(可選)
  7. Redis Desktop Manager(可選)
  8. Node.js(可選)
  9. Bower(可選)

Clone代碼到本地

執(zhí)行命令git clone https://github.com/dotnet/eShopOnContainers.gitclone代碼到本地。使用默認DEV分支即可,該分支會保持最新改動,不要切換到其他分支。

git clone

環(huán)境設置

  1. 給Docker分配CPU和內存
    溫馨提示:以下的配置是最低需求,否則不保證項目能正常運行!

    內存和CPU設置

  2. 設置共享驅動器


    驅動器共享
  3. 設置鏡像加速
    DaoCloud提供的鏡像加速地址http://f1361db2.m.daocloud.io加到"registry-mirrors"的數(shù)組里,點擊 Apply 。

    鏡像加速

  4. 勾選試驗功能
    如果遇到這個報錯,Docker: “no matching manifest for windows/amd64 in the manifest list entries”,就勾選下面這個參數(shù)。

    Experimental features

  5. 防火墻設置
    打開代碼路徑,找到cli-windows\add-firewall-rules-for-sts-auth-thru-docker.ps1power shell腳本并執(zhí)行,打開本地防火墻中的端口,以便對STS(Security Token Service container)進行身份驗證。

    eShopOnContainers 防火墻入站規(guī)則設置

構建并部署到本機Docker主機

進入eShopOnContainers根目錄,執(zhí)行docker-compose build

構建

去喝幾杯咖啡或者打個盹吧,估計得好一會。完成后,執(zhí)行docker image,可以查看已經(jīng)構建好的鏡像。

鏡像列表

PS:你可能會看到很多為<none>的鏡像,這些是臨時鏡像,可以通過命令docker rmi $(docker images -f "dangling=true" -q)刪除。

接下來執(zhí)行docker-compose up命令部署到本地Docker主機。

運行鏡像

啟動完成后,執(zhí)行docker ps命令查看已啟動的容器列表。

運行中的容器列表

本地訪問http://localhost:5100/,即可打開MVC Web應用。如下圖所示:

MVC Web

測試所有應用程序和微服務

一旦完成容器部署,就可以從本地開發(fā)機器通過一下URL或連接字符串任何服務。

  • Web MVC: http://localhost:5100
  • Web Spa: http://localhost:5104
  • Catalog microservice(產(chǎn)品目錄微服務): http://localhost:5101 (Not secured)
  • Ordering microservice(訂單微服務): http://localhost:5102 (Requires token for authorization)
  • Basket microservice(購物車微服務: http://localhost:5103 (Requires token for authorization)
  • Identity microservice(認證授權微服務): http://localhost:5105
  • Web Status(健康檢查): http://localhost:5107
  • Orders database (訂單數(shù)據(jù)庫)(SQL Server connection string): Server=tcp:localhost,5432;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;
  • Catalog database (產(chǎn)品目錄數(shù)據(jù)庫)(SQL Server connection string): Server=tcp:localhost,5434;Database=CatalogDB;User Id=sa;Password=Pass@word
  • ASP.NET Identity database(身份數(shù)據(jù)庫) (SQL Server connection string): Server=localhost,5433;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word
  • Basket data(購物車數(shù)據(jù)) (Redis): listening at localhost:6379

其他

1. 如何從外部連接SQL Server數(shù)據(jù)庫
Server:localhost,5433 (這里是逗號,不是冒號?。。。?/strong>
User:sa
Pwd:Pass@word

連接到容器內SQL Server數(shù)據(jù)庫


2. 構建報錯問題
構建eshop/webspa鏡像時可能會報一下錯誤:
npm ERR! 404 Not Found: event-stream@https://registry.npmjs.org/event-stream/-/event-stream-3.3.6.tgz
解決方案是刪除WebSap項目下的package-lock.json文件,重新構建即可

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容