简体   繁体   English

ASP.NET Core 应用程序不会在容器中启动

[英]ASP.NET Core app won't start in container

I have an ASP.NET Core app which I'm trying to deploy in a docker container.我有一个 ASP.NET Core 应用程序,我正在尝试将其部署在 docker 容器中。 I have a different container for development, which works fine, but I can't get a production version to work.我有一个不同的开发容器,它工作正常,但我无法让生产版本工作。

The dockerfile (see below) I have is based on the one from here , the application builds just fine, but won't run.我拥有的 dockerfile(见下文)基于这里的一个,应用程序构建得很好,但无法运行。 I get the following error:我收到以下错误:

web_1  |   It was not possible to find any installed .NET Core SDKs
web_1  |   Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
web_1  |       https://aka.ms/dotnet-download

After which the container terminates with code 145.之后容器以代码 145 终止。

Dockerfile.prod: Dockerfile.prod:

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

RUN curl -sL https://deb.nodesource.com/setup_13.x |  bash -
RUN apt-get install -y nodejs unzip libc6-dev libgdiplus

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

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

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
RUN mkdir -p /openld-data/fixture-images
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "openld.dll"]

docker-compose.yml docker-compose.yml

version: "3.3"

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile.prod
    ports:
      - "5000:5000"
    depends_on:
      - db
    volumes:
      - ./:/app
      - openld-data:/openld-data
  db:
    image: "postgres:12.1"
    environment:
        POSTGRES_DB:
        POSTGRES_USER:
        POSTGRES_PASSWORD:
    ports:
      - "5432:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data
volumes:
  postgres-data:
  openld-data:

I don't know why it isn't working, the sample ASP.NET containers do something very similar and work just fine.我不知道为什么它不起作用,示例 ASP.NET 容器做了一些非常相似的事情并且工作得很好。 If anyone knows what causes this, any help would be greatly appreciated.如果有人知道这是什么原因,任何帮助将不胜感激。

Your problem seems to be this line:你的问题似乎是这一行:

 volumes:
  - ./:/app

It maps your local current drive to containers /app .它将您当前的本地驱动器映射到容器/app So instead the executable you've built in container, you're using the one built on your machine.因此,您使用的是在您的机器上构建的可执行文件,而不是您在容器中构建的可执行文件。 Delete the - ./:/app and give it a try.删除- ./:/app并尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM