Creating a new Asp.net Core project with Linux container:
Dockerfile:
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY *.sln ./
COPY WebApplication1/WebApplication1.csproj WebApplication1/
RUN dotnet restore
COPY . .
WORKDIR /src/WebApplication1
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
docker-compose.yml:
version: '3'
services:
webapplication1:
image: corewithdocker
build:
context: .
dockerfile: WebApplication1/Dockerfile
After running the application, it creates the corewithdocker:dev image, then I call docker run -p 8888:80 corewithdocker:dev
, the container exited immediately, why? The ENTRYPOINT is ["dotnet", "WebApplication1.dll"]
, shouldn't the container keep running? (call dotnet webapplication1.dll manually, it keeps running unless press ctrl+c).
If I call docker run -dit -p 8888:80 corewithdocker:dev
, the container is up, but I can't access localhost:8888
, do not know the reason.
Is this line "FROM microsoft/aspnetcore:2.0 AS base WORKDIR /app EXPOSE 80" part of your dockerfile . Either way the port 80 is not exposed in the docker image hence your image is existing when trying to bind port 8080 to internal port 80 . add the line expose 80 to your docker file.
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
EXPOSE 80
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.