Docker: Unable to run .net core api with docker-compose : exited with code 145

♀尐吖头ヾ 提交于 2020-04-30 06:35:06

问题


I am trying to run .net core api in a docker container but I am getting the following error:

My first guess looking at the error is that it's because it is not able to find .net core sdk. But as you can see I have included sdk in my dockerfile: FROM mcr.microsoft.com/dotnet/core/aspnet:2.2

Dockerfile

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
EXPOSE 80/tcp

WORKDIR /app
COPY --from=build-env /app/out .

 ENTRYPOINT ["dotnet", "ApiForDocker.dll"]

docker-compose.yml

version: '3'
services:
  coreapi:    
    build: 
      context: .
      dockerfile: Dockerfile      
    ports:
      - "4002:5000"
    volumes:
      - .:/app

回答1:


Okay I solved by removing :

  volumes:
      - .:/app

from my docker-compose.yml:

version: '3'
services:
  coreapi:    
    build: 
      context: .
      dockerfile: Dockerfile      
    ports:
      - "4002:5000"        

I guess the problem was that I building code with my dockerfile but then in docker compose I was basically saying that I want to use my source code outside to be used. It might work in nodejs but I am not sure how to use prebuilt .net code code as volume.



来源:https://stackoverflow.com/questions/60898187/docker-unable-to-run-net-core-api-with-docker-compose-exited-with-code-145

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!