【问题标题】:docker: entrypoint is not executingdocker:入口点未执行
【发布时间】:2018-07-16 15:38:16
【问题描述】:

我有以下 dockerfile:

# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY ./entrypoint.sh ./app/
RUN chmod +x ./app/entrypoint.sh
CMD /bin/bash ./app/entrypoint.sh
ENTRYPOINT ["dotnet", "test.dll"]

并希望 entrypoint.sh 正在执行。但我得到了错误:

Unhandled Exception: System.FormatException: Value for switch '/bin/bash ./app/entrypoint.sh' is missing.
Test          |    at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load()
Test          |    at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
Test          |    at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
Test          |    at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
Test          |    at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
Test          |    at Test.Program.Main(String[] args) in /app/Program.cs:line 19
Identity exited with code 139

这是什么意思:switch 的值丢失了,我怎样才能让它运行?感谢您的帮助

更新

请参阅此处:docker asp.net core container starting after a mysql container 了解更多信息。对不起,类似的第二个线程。请删除此贴

更新 2

这是我的 entrypoint.sh:

#!/bin/bash

set -e
echo -e "\nWaiting for the Database-Service..."
run_cmd="dotnet run --server.urls http://*:80"

until dotnet ef database update; do
>&2 echo "SQL Server is starting up"
sleep 1
done

>&2 echo "SQL Server is up - executing command"
exec $run_cmd

似乎 dotnet ef 数据库更新不起作用。所以我收到错误消息:

SQL Server is starting up
Test          | Did you mean to run dotnet SDK commands? Please install dotnet SDK from: 
Test          |   http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

这不是因为找不到 test.dll 而导致的错误吗?

【问题讨论】:

  • 您想在容器中运行哪个命令:1. /bin/bash ./app/entrypoint.sh 或 2. dotnet test.dll 或它们的某种组合?
  • 请张贴entrypoint.sh的内容以澄清预期结果。
  • 对不起第二个线程。请看这里:stackoverflow.com/questions/51359885/…

标签: docker docker-compose dockerfile


【解决方案1】:

正在发生的事情是 dotnet test.dll 正在使用参数 /bin/bash ./app/entrypoint.sh 启动。然后您的 Test 程序尝试解析这些参数并失败。这就是异常的意义所在。

您可能必须根据您要实现的目标删除CMDENTRYPOINT。您还可以交换CMDENTRYPOINT 参数如果 entrypoint.sh 旨在接收dotnet test.dll 作为参数。

【讨论】:

    【解决方案2】:

    因为 ENTRYPOINT 始终位于 CMD 的前缀,即使您更改了顺序。所以启动命令变成了这样:

    dotnet test.dll /bin/bash ./app/entrypoint.sh 
    

    这当然会引发错误。因此,您应该将 dockerfile 更改为如下所示:

    # Build runtime image 
    FROM microsoft/aspnetcore:2.0 
    WORKDIR /app 
    COPY ./entrypoint.sh ./app/ 
    RUN chmod +x ./app/entrypoint.sh 
    ENTRYPOINT ["/bin/bash", "./app/entrypoint.sh"]
    CMD ["dotnet", "test.dll"]
    

    应该允许你的容器启动

    这有两个原因。

    由于 CMD 和 ENTRYPOINT 的排列顺序问题,因此所需的命令确实是

    /bin/bash ./app/entrypoint.sh dotnet test.dll
    

    但是 docker 总是把 ENTRYPOINT 放在 CMD 之前,不管它们在物理上是如何排列的,所以通过切换两者我们能够得到想要的命令。请对比一下原来和新的dockerfile,只有一处改动。

    所以这是一个语法问题,而不是一个实际的技术问题,尽管https://stackoverflow.com/a/41518225/8554496,请阅读这个堆栈溢出答案

    【讨论】:

    • 这不只是将dotnet test.dll 传递给entrypoint.sh 作为参数吗?你能解释一下这是如何工作的吗?
    • 谢谢你的作品。像 r3mus n0x 问。你能解释一下为什么吗?
    • 我已经编辑尝试解释它为什么有效,但它确实应该是直截了当的,我添加了一个详细讨论 CMD 和 ENTRYPOINT 的链接
    • 所以在提供的链接中它可以工作,因为脚本以exec "$@" 结尾,这意味着执行传递给脚本的任何参数。然而,在这个容器中,脚本以exec $run_cmd 结尾,其中run_cmd="dotnet run --server.urls http://*:80"。所以我仍然不知道它会如何启动dotnet test.dll
    • 至少他找到了 entrypoint.sh 但之后我得到:SQL Server is starting up Did you mean to run dotnet SDK commands? Please install dotnet SDK from: 所以似乎没有找到 test.dll
    猜你喜欢
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多