dotnet aspnetcore docker构建失败并显示145错误代码 [英] dotnet aspnetcore docker build fails with a 145 error code

查看:454
本文介绍了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 http://*: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 http://*: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:
  http://go.microsoft.com/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:

https://hub.docker.com/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"]

请注意,现在<在映像中运行的code> 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错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆