尝试连接到docker上的aspnet核心应用程序时拒绝Localhost连接

时间:2019-07-30 10:29:51

标签: asp.net docker docker-compose

我使用Docker Toolbox是因为我赢得了10家庭版。

有我的docker-compose文件:

version: "3.2"

networks:
   frontend:
   backend:

services:
   catalog:
      build:
         context: .\src\Services\ProductCatalogApi
         dockerfile: Dockerfile
      image: microservices-v1.0.0
      environment:
         - DatabaseServer=mssqlserver
         - DatabaseName=CatalogDb
         - DatabaseUser=sa
         - DatabaseUserPassword=ProductApi(!)
      container_name: catalogapi
      ports:
         - "5000:80"
      networks:
         - backend
         - frontend
      depends_on:
         - mssqlserver

   mssqlserver:
      image: "microsoft/mssql-server-linux:latest"
      ports:
         - "2200:1433"
      container_name: mssqlcontainer
      environment:
         - ACCEPT_EULA=Y
         - SA_PASSWORD=ProductApi(!)
      networks:
         - backend

我也有一个运行良好的mssqlserver实例,我可以毫无问题地通过地址ip连接到它。

Dockerfile:

FROM microsoft/aspnetcore-build:2.0.0 AS build

WORKDIR /code

COPY . .

RUN dotnet restore

RUN dotnet publish --output /out/ --configuration Release

FROM microsoft/aspnetcore:2.0.0

COPY --from=build /out /app/

WORKDIR  /app

ENTRYPOINT ["dotnet","ProductCatalogApi.dll"]

到目前为止我尝试过什么?

  1. Can't connect to ASP.NET core through docker
    在Program.cs文件中定义.UseUrls
  2. Unable to access Docker application from browser
  3. 通过以下方式连接:localhost:5000 / swagger,addrress_ip / swagger(我通过docker inspect获得地址),address_ip:5000 / swagger

我的源代码:
https://github.com/AGranosik/microservices-udemy-v2

1 个答案:

答案 0 :(得分:0)

在Win 10 Home上使用docker时,您唯一需要做的就是通过VM机器的cmd地址进行检查(默认)。 指令:

docker-machine ls

然后,您将计算机的ip放在端口而不是本地主机的前面。