【问题标题】:Windows Container (Nano Server) with ASP.NET Core带有 ASP.NET Core 的 Windows 容器(纳米服务器)
【发布时间】:2017-10-17 16:59:24
【问题描述】:

我正在尝试创建一个运行 ASP.NET Core 应用程序的 Windows Nano Server 容器。
我正在 Windows Server 2016 上构建它。我可以让它工作,但有一个奇怪的问题。

我可以让它工作的唯一方法是构建映像,运行容器,然后启动交互式 Powershell 会话并使用Invoke-WebRequest http://localhost:5000。一旦我从容器内部执行此操作,该应用程序就可以从其他服务器看到(由于已知的 NAT 错误,我无法从 Win2016 服务器本地浏览容器。)

这是我的 Dockerfile:

FROM microsoft/dotnet:sdk-nanoserver
ARG source
WORKDIR /app
COPY /ContainerPOC/ .
RUN dotnet restore --runtime win10-x64 .

RUN dotnet build --framework netcoreapp1.1 --runtime win10-x64 .

EXPOSE 5000
ENV ASPNETCORE_URLS http://0.0.0.0:5000
CMD dotnet run --framework netcoreapp1.1

知道为什么这不能“正常工作”吗?

【问题讨论】:

    标签: windows docker containers


    【解决方案1】:

    这对我有用:

    λ  cat .\Dockerfile
    FROM microsoft/dotnet:2.0.0-preview1-sdk-nanoserver
    
    WORKDIR /app
    RUN dotnet new mvc
    RUN dotnet restore
    RUN dotnet build
    ENV ASPNETCORE_URLS http://0.0.0.0:5000
    CMD dotnet run
    
    C:\code\repros\dotnet-sample
    λ  docker build -t test .
    Sending build context to Docker daemon  2.048kB
    Step 1/7 : FROM microsoft/dotnet:2.0.0-preview1-sdk-nanoserver
     ---> d92a15cb72c5
    Step 2/7 : WORKDIR /app
     ---> Using cache
     ---> 7405c251e8ee
    Step 3/7 : RUN dotnet new mvc
     ---> Using cache
     ---> a13bf888f48a
    Step 4/7 : RUN dotnet restore
     ---> Using cache
     ---> f760754eaf62
    Step 5/7 : RUN dotnet build
     ---> Using cache
     ---> 5d661f94ef39
    Step 6/7 : ENV ASPNETCORE_URLS http://0.0.0.0:5000
     ---> Using cache
     ---> a912538a46a9
    Step 7/7 : CMD dotnet run
     ---> Using cache
     ---> 0b3712d69dae
    Successfully built 0b3712d69dae
    Successfully tagged test:latest
    C:\code\repros\dotnet-sample
    λ  docker run --name test -d -p 5000:5000 test^C
    C:\code\repros\dotnet-sample
    λ  docker rm -f test
    test
    C:\code\repros\dotnet-sample
    λ  docker build -t test .^C
    C:\code\repros\dotnet-sample
    λ  docker run --name test -d -p 5000:5000 test
    73dfc9706edb9d7956d0bc43113994066baad0f07db29b7a81f60a11e14d9e3a
    C:\code\repros\dotnet-sample
    λ  docker inspect --format "{{.NetworkSettings.Networks.nat.IPAddress}}" 73
    172.17.59.102
    C:\code\repros\dotnet-sample
    λ  iwr -UseBasicParsing http://172.17.59.102:5000/
    
    
    StatusCode        : 200
    StatusDescription : OK
    ...
    

    Linux 示例如下

    cat .\Dockerfile
    FROM microsoft/dotnet:2.0-sdk
    
    WORKDIR /app
    RUN dotnet new mvc
    RUN dotnet restore
    RUN dotnet build
    ENV ASPNETCORE_URLS http://0.0.0.0:5000
    CMD dotnet run
    

    docker build -t test . Sending build context to Docker daemon 2.048kB Step 1/7 : FROM microsoft/dotnet:2.0-sdk ---> aeb44045bdf4 Step 2/7 : WORKDIR /app ---> Using cache ---> 40d8474d3ff1 Step 3/7 : RUN dotnet new mvc ---> Using cache ---> 8447728b31dc Step 4/7 : RUN dotnet restore ---> Using cache ---> 81bbf373ae60 Step 5/7 : RUN dotnet build ---> Using cache ---> 95a83c304b53 Step 6/7 : ENV ASPNETCORE_URLS http://0.0.0.0:5000 ---> Using cache ---> 9a265a927356 Step 7/7 : CMD dotnet run ---> Using cache ---> a962d986f3a6 Successfully built a962d986f3a6 Successfully tagged test:latest

    docker run --name test -d -p 5000:5000 test 61ff30bc7488a0390af26a7a881fb4704d092ec89c49030d1935176b94e92a20

    docker inspect --format "{{.NetworkSettings.Networks.nat.IPAddress}}" 61ff
    172.17.52.83
    iwr -UseBasicParsing http://172.17.52.83:5000/
    
    
    StatusCode        : 200
    StatusDescription : OK
    

    【讨论】:

    • 那是一个基于linux的容器。我正在尝试构建 Nano Server 容器。
    • 对不起,我的错 - 它也适用于我,更新了示例。
    • 谢谢,我会试一试,告诉你进展如何
    猜你喜欢
    • 2021-10-30
    • 1970-01-01
    • 2019-05-25
    • 2016-06-30
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 2018-06-30
    相关资源
    最近更新 更多