环境准备
Win10(开启Hyper-V)
.NET Core SDK
Docker for Windows
VS2017 or VS Code
Git
SQL Server Management Studio(可选)
Redis Desktop Manager(可选)
Node.js(可选)
Bower(可选)
Clone代码到本地
执行命令 git clone https://github.com/dotnet/eShopOnContainers.gitclone代码到本地。使用默认 DEV分支即可,该分支会保持最新改动,不要切换到其他分支。
环境设置
给Docker分配CPU和内存温馨提示:以下的配置是最低需求,否则不保证项目能正常运行!
设置共享驱动器
设置镜像加速 把DaoCloud提供的镜像加速地址
http://f1361db2.m.daocloud.io加到"registry-mirrors"的数组里,点击 Apply 。勾选试验功能 如果遇到这个报错,Docker: “no matching manifest for windows/amd64 in the manifest list entries”,就勾选下面这个参数。
防火墙设置 打开代码路径,找到
cli-windows\add-firewall-rules-for-sts-auth-thru-docker.ps1power shell脚本并执行,打开本地防火墙中的端口,以便对STS(Security Token Service container)进行身份验证。
构建并部署到本机Docker主机
进入eShopOnContainers根目录,执行 docker-compose build。
去喝几杯咖啡或者打个盹吧,估计得好一会。完成后,执行 docker image,可以查看已经构建好的镜像。
PS:你可能会看到很多为 <none>的镜像,这些是临时镜像,可以通过命令 docker rmi $(docker images-f"dangling=true"-q)删除。
接下来执行 docker-compose up命令部署到本地Docker主机。
启动完成后,执行 docker ps命令查看已启动的容器列表。
本地访问http://localhost:5100/,即可打开MVC Web应用。如下图所示:
测试所有应用程序和微服务
一旦完成容器部署,就可以从本地开发机器通过一下URL或连接字符串任何服务。
Web MVC: http://localhost:5100
Web Spa: http://localhost:5104
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
Web Status(健康检查): http://localhost:5107
Orders database (订单数据库)(SQL Server connection string):
Server=tcp:localhost,5432;Database=Microsoft.eShopOnContainers.Services.OrderingDb;UserId=sa;Password=[email protected];Catalog database (产品目录数据库)(SQL Server connection string):
Server=tcp:localhost,5434;Database=CatalogDB;UserId=sa;Password=[email protected]ASP.NET Identity database(身份数据库) (SQL Server connection string):
Server=localhost,5433;Database=aspnet-Microsoft.eShopOnContainers;UserId=sa;Password=[email protected]Basket data(购物车数据) (Redis): listening at localhost:6379
其他
PS:关于如何从外部连接SQL Server数据库,使用: Server:localhost,5433 (这里是逗号,不是冒号!!!)
User:sa Pwd:[email protected]