dotnet aspnetcore docker build fails with a 145 error code

元气小坏坏 提交于 2019-12-01 03:37:28

The image you are using contains the .NET Core runtime only, not the SDK. Try a base image from the following repository:

https://hub.docker.com/r/microsoft/aspnetcore-build/


Your Dockerfile has the following lines in it:

RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]

Which means that the dotnet restore and dotnet build commands are running within the image you're using. As the image you are using doesn't have the SDK installed, these commands cannot be found and fail as you're seeing. The images in the repository I linked above have the SDK installed within them and so the dotnet restore and dotnet build commands can be found and executed.

The alternative to using a base image with the SDK installed would be to perform the build/publish process on your development machine and then simply copy the published output into the image. Your Dockerfile would then only need to look something along the lines of:

FROM microsoft/aspnetcore:1.0.1
WORKDIR /app
COPY ./app .
ENTRYPOINT ["dotnet", "TheNameOfYourProject.dll"]

Note that now the dotnet commands run within the image is simply the one that runs your (pre-built) DLL. This only requires the runtime, and not the SDK.

I received this error because of a difference between the Dockerfile and docker-compose.yml.

Dockerfile (original):

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
...

I changed the Dockerfile to move files to nginx's default directory...

Dockerfile (change):

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /usr/share/nginx/html
...

But the docker-compose.yml referenced the old folder...

docker-compose.yml (original):

services:
  web:
    working_dir: /app

To fix it, just update the working_dir to point to the new directory...

docker-compose.yml (fix):

services:
  web:
    working_dir: /usr/share/nginx/html

In my case was an stupid error, but maybe can help someone. I changed the project name and this broked the docker compose. So, the folder of the web app, the project (it is the .csproj file) and the DLL to run with dotnet should have the same name in my case, because I am using one variable in the dockerfile that assumes that. In summary review carefully the names we are using for each thing.

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