启动时出现 Dotnetcore 容器错误,询问我是否要运行 SDK 命令 [英] Dotnetcore container errors on startup asking if I mean to run SDK commands

查看:26
本文介绍了启动时出现 Dotnetcore 容器错误,询问我是否要运行 SDK 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的 dotnetcore 2.0 应用程序,我想对其进行容器化.这个容器将在部署时运行一次以执行一些应用程序配置任务.

I'm creating a simple dotnetcore 2.0 application and I want to containerize it. The idea being this container will run once on deployment to do some application configuration tasks.

目前,代码就是这样做的...

At present, the code just does this...

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
    }
}

docker 文件看起来像这样...

The docker file looks like this...

FROM microsoft/dotnet:2.0-runtime
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "consoleapp.dll"]

我在 Visual Studio 2017 中按了 F5,我可以通过执行 docker image ls 命令看到容器存在.

I hit F5 in Visual Studio 2017 and I can see by doing a docker image ls command that the container exists.

然后我尝试按如下方式运行容器:

I then attempt to run the container as follows:

docker run consoleapp: dev

我现在收到错误:

Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
  http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

我的想法是,因为我使用运行时映像作为我的映像的基础,所以我应该能够以某种方式启动我的应用程序.我猜这里的错误是 dotnet 构成我的入口点的一部分是 dotnet SDK 的一部分,因此不在我的基本映像中.

My thinking on this is that because I am using a runtime image to base my image on, I should be able to somehow start my application. I'm guessing the error here is that dotnet which forms part of my entry point is part of the dotnet SDK and hence is not in my base image.

我应该将此容器基于 dotnet 核心的非运行时版本吗?

Should I base this container on a non-runtime version of the dotnet core?

推荐答案

您会看到此错误消息的一个原因是当传递给 dotnet 的参数未知时.

One reason why you can see this error message is when the argument passed to dotnet is unknown.

runtime 无法识别您传递给它的参数,并想知道您是否应该改用 sdk.

The runtime doesn't recognize the argument you are passing to it and wonder if you perhaps should be using the sdk instead.

确保 dll 的名称及其路径在以下位置正确:

Make sure the name of the dll and the path to it are correct in:

ENTRYPOINT ["dotnet", "consoleapp.dll"]

另外,请确保 COPY 指令按预期工作.

Also, make sure the COPY instruction works as expected.

在您的示例中,它从 obj/Docker/publish 文件夹中选取文件.准备执行的输出应该来自 bin 文件夹.如果您使用的是已发布版本,请确保在创建容器之前运行 dotnet publish.或者在创建镜像时恢复/构建/发布.

In your example it's picking files from the obj/Docker/publish folder. The output ready to be executed should come out of the bin folder instead. If you are using the published version, make sure to run dotnet publish before creating the container. Or restore/build/publish when creating the image.

请记住,dll 必须完全位于 WORKDIR 处.在你的情况下:/app除非您提供 dotnet

Remember the dll would have to end up exactly at the WORKDIR. In your case: /app Unless you provide the path to dotnet

我在 Github 上创建了一个 基本工作示例:

I've created a basic working sample on Github:

这篇关于启动时出现 Dotnetcore 容器错误,询问我是否要运行 SDK 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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