dotnet aspnetcore docker构建失败并显示145错误代码

编程入门 行业动态 更新时间:2024-10-23 21:24:57
本文介绍了dotnet aspnetcore docker构建失败并显示145错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已使用本教程创建我的第一个docker webapi项目。

I've used this tutorial to create my first docker webapi project.

我正在使用Windows 7(docker工具箱)。

I'm using windows 7 (docker toolbox).

这是我所运行的:

dotnet new webapi

这是Dockerfile:

This is the Dockerfile:

FROM microsoft/dotnet:latest COPY . /app WORKDIR /app RUN ["dotnet", "restore"] RUN ["dotnet", "build"] EXPOSE 5000/tcp ENV ASPNETCORE_URLS *:5000 ENTRYPOINT ["dotnet", "run"]

这是我创建映像的方式:

This is how I created the image:

docker build -t mydemos:aspnetcorehelloworld .

这就是我创建和运行容器的方式:

And this is how I've created and ran the container:

docker run -d -p 8080:5000 -t mydemos:aspnetcorehelloworld

我的服务已成功作为docker容器运行。

然后,我尝试更改Dockerfile以使其正常运行一个aspnetcore基本映像:

Then, I tried changing the Dockerfile to work on a aspnetcore base image:

FROM microsoft / dotnet:latest 更改为 FROM microsoft /aspnetcore:1.0.1

新的Dockerfile如下:

The new Dockerfile looks like:

FROM microsoft/aspnetcore:1.0.1 COPY . /app WORKDIR /app RUN ["dotnet", "restore"] RUN ["dotnet", "build"] EXPOSE 5000/tcp ENV ASPNETCORE_URLS *:5000 ENTRYPOINT ["dotnet", "run"]

现在,我尝试使用

docker build -t mydemos:aspnetcorehelloworld1 .

我得到一个错误。这是构建日志:

And I get an error. This is the build log:

Sending build context to Docker daemon 636.9 kB Step 1/8 : FROM microsoft/aspnetcore:1.0.1 ---> 2c7bbc508bb2 Step 2/8 : COPY . /app ---> Using cache ---> 1d5b9bd908b3 Step 3/8 : WORKDIR /app ---> Using cache ---> c1d5d091d111 Step 4/8 : RUN dotnet restore ---> Running in 8399e21caeb2 Did you mean to run dotnet SDK commands? Please install dotnet SDK from: go.microsoft/fwlink/?LinkID=798306&clcid=0x409 The command 'dotnet restore' returned a non-zero code: 145

我进入了url,重新安装了东西,但仍然出现错误。 我尝试在同一命令行会话中使用dotnet cli命令,但我成功了( dotnet restore 可以工作)。

I went into the url, reinstalled stuff and I still get an error. I've tried to use the dotnet cli commands in the same command line session and I succeed (dotnet restore works).

我尝试搜索此错误,但是找不到真正的解决方案。

I've tried to search this error around, but couldn't really find any solution.

我在这里缺少什么?我在多个场合和测试中都遇到了145错误。

What am I missing here? I'm getting this 145 error on multiple occasions and tests.

推荐答案

您使用的映像仅包含.NET Core运行时,而不是SDK。尝试从以下存储库中获取基本映像:

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

hub.docker/r/microsoft/aspnetcore-build/

您的Dockerfile中包含以下行:

Your Dockerfile has the following lines in it:

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

这意味着 dotnet恢复和 dotnet构建命令正在您使用的映像中运行。由于您使用的映像未安装SDK,因此您找不到这些命令,这些命令将失败。我在上面链接的资源库中的映像已安装了SDK,因此 dotnet恢复和 dotnet构建命令可以

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.

使用安装了SDK的基础映像的替代方法是在开发计算机上执行构建/发布过程,然后简单地复制已发布的输出到图像中。然后,您的Dockerfile只需看起来类似以下内容:

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"]

请注意,现在 dotnet 命令只是运行您(预构建的)DLL的命令。这只需要运行时,而不需要SDK。

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.

更多推荐

dotnet aspnetcore docker构建失败并显示145错误代码

本文发布于:2023-11-16 09:36:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码   aspnetcore   dotnet   docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!