首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有ASP.NET内核的Windows容器(Nano )

带有ASP.NET内核的Windows容器(Nano )
EN

Stack Overflow用户
提问于 2017-05-18 03:48:34
回答 1查看 885关注 0票数 0

我正在尝试制作一个运行ASP.NET核心应用程序的容器。

我正在Windows Server 2016上构建它。我可以让它发挥作用,但有一个奇怪的问题。

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

这是我的Dockerfile:

代码语言:javascript
复制
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

你知道为什么这不会“奏效”吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-18 18:08:34

这对我来说很管用:

代码语言:javascript
复制
λ  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示例

代码语言:javascript
复制
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

代码语言:javascript
复制
docker inspect --format "{{.NetworkSettings.Networks.nat.IPAddress}}" 61ff
172.17.52.83
iwr -UseBasicParsing http://172.17.52.83:5000/


StatusCode        : 200
StatusDescription : OK
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44038266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档