简体   繁体   中英

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 . This application is packed into a Docker container, which is a part of the docker-compose scenario. The ENTRYPOINT of that dockerfile looks like this:

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.

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 . If I use CMD in the combination with the ENTRYPOINT , it doesn't have any effect:

ENTRYPOINT ["dotnet", "Benchmarks.dll"]
CMD [ "-f", "*" ]

I need to run it on CI, so the default args should always be passed.

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. It turns out that when I run it from docker-compose , it doesn't print anything. The service definition in docker-compose.yml is quite simple, it just references the 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)

using System;

namespace app
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (var arg in args)
            {
                Console.WriteLine(arg);
            }
        }
    }
}

And my 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM