[英]Command-line arguments are not passed to the Docker container entrypoint
I created a console application to run benchmark tests with the Benchmark.Net library .我创建了一个控制台应用程序来运行Benchmark.Net 库的基准测试。 This application is packed into a Docker container, which is a part of the docker-compose scenario.这个应用程序被打包到一个 Docker 容器中,它是 docker-compose 场景的一部分。 The ENTRYPOINT
of that dockerfile
looks like this:该ENTRYPOINT
的dockerfile
如下所示:
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Benchmarks.dll", "-f", "*"]
These args instruct the Benchmark.Net library to run all tests in that assembly.这些参数指示 Benchmark.Net 库运行该程序集中的所有测试。
The problem : the arguments are never passed to the console app.问题:参数永远不会传递给控制台应用程序。 The docker-compose doesn't have command
or entrypoint
elements, it just references the dockerfile
. docker-compose 没有command
或entrypoint
元素,它只是引用dockerfile
。 If I use CMD
in the combination with the ENTRYPOINT
, it doesn't have any effect:如果我将CMD
与ENTRYPOINT
结合使用,它没有任何效果:
ENTRYPOINT ["dotnet", "Benchmarks.dll"]
CMD [ "-f", "*" ]
I need to run it on CI, so the default args should always be passed.我需要在 CI 上运行它,因此应始终传递默认参数。
What am I doing wrong?我究竟做错了什么? How to make it work?如何使它工作?
UPDATE: If I run it with the pure docker run
command, it works just fine and gets the passed arguments.更新:如果我使用纯docker run
命令运行它,它就可以正常工作并获取传递的参数。 It turns out that when I run it from docker-compose
, it doesn't print anything.事实证明,当我从docker-compose
运行它时,它不会打印任何内容。 The service definition in docker-compose.yml
is quite simple, it just references the Dockerfile
: docker-compose.yml
的服务定义非常简单,它只是引用了Dockerfile
:
benchmarks:
build:
context: ../
dockerfile: test/Benchmarks/Dockerfile
args:
- NUGET_SOURCE
depends_on:
- another.service
environment:
- ASPNETCORE_ENVIRONMENT=Development
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
I tried to reproduce your issue, but I can't.我试图重现你的问题,但我不能。
Here's my program (I did dotnet new console
and changed Program.cs to this)这是我的程序(我做了dotnet new console
并将 Program.cs 更改为这个)
using System;
namespace app
{
class Program
{
static void Main(string[] args)
{
foreach (var arg in args)
{
Console.WriteLine(arg);
}
}
}
}
And my Dockerfile还有我的 Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:5.0 as publish
WORKDIR /app
COPY . ./
RUN dotnet publish -o out app.csproj
FROM mcr.microsoft.com/dotnet/runtime:5.0
WORKDIR /app
COPY --from=publish /app/out .
ENTRYPOINT ["dotnet", "app.dll", "-f", "*"]
I then build and run it with然后我构建并运行它
docker build -t test .
docker run --rm test
and it prints它打印
-f
*
like you'd expect.就像你期望的那样。
So the arguments are passed to the program.所以参数被传递给程序。 Your issue might be that you don't pass them correctly to Benchmark?您的问题可能是您没有将它们正确传递给 Benchmark?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.