我正在尝试将简单的REST Api(基于asp.net核心构建)放入Docker容器。
我有以下docker文件
function sumAll(startNum, endNum) {
var sumNum = 0;
for (var i = startNum; i <= endNum; i++) {
sumNum += i;
}
return sumNum;
}
console.log(sumAll(1, 3));
我可以成功地从该文件构建图像,但是例如,当我运行容器时,我无法调用任何URL,而我在API上方却大摇大摆,因此它应该向我显示一个页面,但是不是。
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["/", "SimpleApp.Api/"]
RUN dotnet restore "SimpleApp.Api/SimpleApp.Api.csproj"
COPY . .
WORKDIR "/src/SimpleApp.Api"
RUN dotnet build "SimpleApp.Api.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "SimpleApp.Api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SimpleApp.Api.dll"]
像docker run -d --name "mySimpleContainer" "MySimpleApp:latest" --ports 5000:80
这样的网址无法正常工作,因此我首先检查了日志:
localhost:5000
对我来说看起来不错。中学,我检查了5000是否忙...突然之间不是!
检查我使用的端口........
2019-02-02 13:37:17.3635||DEBUG|Microsoft.AspNetCore.Hosting.Internal.WebHost|Loaded hosting startup assembly SimpleApp.Api
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
有人知道我失败了吗?