Docker:无法与docker-compose一起运行.net核心api:已退出,代码145 [英] Docker: Unable to run .net core api with docker-compose : exited with code 145
问题描述
我正在尝试在Docker容器中运行.net核心api,但出现以下错误:
I am trying to run .net core api in a docker container but I am getting the following error:
我首先看到的错误是因为它找不到.net core sdk。但是正如您所看到的,我在dockerfile中包含了sdk:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
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
推荐答案
好了,我删除了:
volumes:
- .:/app
-compose.yml:
from my docker-compose.yml:
version: '3'
services:
coreapi:
build:
context: .
dockerfile: Dockerfile
ports:
- "4002:5000"
我猜问题是我用dockerfile构建代码,但是在docker compose中,我基本上是说我想在外部使用我的源代码。它可能在nodejs中可用,但是我不确定如何将预构建的.net代码用作卷。
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.
这篇关于Docker:无法与docker-compose一起运行.net核心api:已退出,代码145的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!