一、 核心步驟
- Git clone https://github.com/dotnet-architecture/eShopOnContainers.git
git 克隆 項目 - Open solution eShopOnContainers-ServicesAndWebApps.sln with VS2017
打開指定項目 - Set the VS startup project to the "docker-compose" project
設置啟動項目 - Hit F5!
運行項目
起始要真的這么簡單就好了,坑實在是多,下面開始一個一個排吧
二、Windows 下其他配套軟件配置
- Hyper-V
Windows 10 自帶,只需要用 power-Shell 開啟就行。裝這個還是為了 Docker 的正常運行
- 使用超管運行 power-shell ,敲入命令:
Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All
-
Docker ce for Windows
直接上官網下載安裝 -
Docker 配置
- docker for windows 是使用 Hyper-v 運行了一個 Linux 虛擬,所以 Hyper-v 是必須的。
要注意虛擬機系統互相打架,下面信息我就不翻譯了:
IMPORTANT: Check that you don't have any other hypervisor installed that might be not compatible with Hyper-V. For instance, Intel HAXM can be installed by VS 2017 if you chose to install Google's Android emulator which works on top of Intel HAXM. In that case, you'd need to uninstall Google's Android emulator and Intel HAXM. VS 2017 recommends to install the Google Android emulator because it is the only Android emulator with support for Google Play Store, Google Maps, etc. However, take into account that it currently is not compatible with Hyper-V, so you might have incompatibilities with this scenario.
-
要想此項目中所有的容器運行正常,推薦配置 docker 使用 3 cpu 和 4G 內存
所以,開發機器配置最好是不低於 16G,4核,這是個大坑,一般不玩游戲的程序員,現在用 16G 本子的應該不多吧.... 看來俺的老機器該升級了 -
Shared Drives 這里也是個坑,我編譯了3、4 次沒通過,就是沒有把這塊所有硬盤都選中。也有說必須是選中 C 盤。
其實應該沒必要全部選中,但我的就是跑不起來,有人也說,把復選框取消,再選中,或者重啟可以解決運行項目時的錯誤,暫時沒試 -
Network配置 按默認的就行
-
開啟Windows防火牆指定端口 控制面板 - 防火牆 - 高級設置 - 入站規則
添加 端口 5100-5110
三、 加載項目 運行
最麻煩的還是 docker 這塊設置,如果搞定了,機器配置夠的話,運行還是很順的。
- 設置 docker-compose 為啟動項目,確保 docker 運行中,運行項目
- 成功后,會看到瀏覽器中加載 eshop 網站
- 可以在 power-shell 中,運行命令 docker ps 查看正在運行中的 docker 容器
四、Web SAP 應用配置
If you want to run/test the web eShopOnContainers SPA (Single Page Application) client in adition to the regular MVC Web app, you need to install certain dependencies for the client side and build it with "npm build", as the client side of the SPA app is based on ANGULAR 2, TypeScript and other JS frameworks and compilation that needs to happen before building the Docker images. The process is described in detail here: https://github.com/dotnet-architecture/eShopOnContainers/wiki/06.-Setting-the-Web-SPA-application-up
五、多容器中斷點調試
和正常調試類似,雖然項目運行在 docker 容器中,但是在 vs 源代碼中,添加斷點照樣可以正常進行調試,比較神奇,這也是 vs 2017 的強大之處吧。
六、測試 SPA web APP
七、測試微服務 Swagger
容器運行狀態下,使用 http://localhost:5101 進行測試
八、應用和微服務列表
- Web MVC: http://localhost:5100
測試用戶賬號
User: demouser@microsoft.com
Password: Pass@word1 - Web Spa: http://localhost:5104 (Important, check how to set up the SPA app and requirements before building the Docker images. Instructions at * https://github.com/dotnet/eShopOnContainers/wiki/06.-Setting-the-Web-SPA-application-up)
- Catalog microservice: 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
- Orders database (SQL Server connection string): Server=tcp:localhost,5432;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;
- Catalog database (SQL Server connection string): Server=tcp:localhost,5434;Database=CatalogDB;User Id=sa;Password=Pass@word
- ASP.NET Identity database (SQL Server connection string): Server=localhost,5433;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word
- Basket data (Redis): listening at localhost:6379
九、手機端測試
可以測試 Xamarin app 在真實的 ios、Android 或 windows 設備上,但如果運行 android 虛擬機的話,不能用 google 的,只能用 vs 的,他們互相沖突,會導致 docker 不能用,系統藍屏重啟
You can deploy the Xamarin app to real iOS, Android or Windows devices. You can also test it on an Android Emulator based on Hyper-V like the Visual Studio Android Emulator (Do NOT install the Google's Android emulator or it will break Docker and Hyper-V, as mentioned above).
步驟(團隊暫時用不着,就不翻了):
- Disable mock-services in the Xamarin app by setting the UseMockServices = false in the App.xaml.cs and specify the host IP in BaseEndpoint = "http://10.106.144.28" at the GlobalSettings.cs. Both files in the Xamarin.Forms project (PCL).
- Another alternative is to change that IP through the app UI, by modifying the IP address in the Settings page of the App as shown in the screenshot below.
- In addition, you need to make sure that the used TCP ports of the services are open in the local firewall.