带有ASP.NET Core的Windows容器(Nano Server)

时间:2017-05-18 03:48:34

标签: windows docker containers

我正在尝试制作运行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

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

1 个答案:

答案 0 :(得分: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