0

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

FINAL UPDATE: Unfortunately, I forgot to mention in my initial question that I run it from inside the Visual Studio with dscproj. Apparently, VS adds its own rules about how to run the docker-compose project, overriding the command line.

There's still no proper solution for it, although there's an ugly workaround.

So, my question is a duplicate of this one. Case closed.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • Are you expecting to receive the single argument `*`, or a list of filenames? – David Maze Oct 20 '21 at 12:56
  • 1
    I expect to receive exactly the args I pass in. For example, if I have `ENTRYPOINT ["dotnet", "Benchmarks.dll", "-f", "*"]`, I think I should get 2 elements in the `args` array: "-f", "*" – Yan Sklyarenko Oct 20 '21 at 16:13

1 Answers1

1

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?

Edit: With this docker-compose.yaml file

version: "3.9"
services:
  test:
    image: "test"
    command: ["more", "arguments"]

and docker-compose up (without -d, so it runs in the foreground), it prints all the arguments - both the ones from the entrypoint and the ones from the command.

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • This scenario works for me, too. 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`. I'll update my question with that snippet – Yan Sklyarenko Oct 20 '21 at 16:08
  • @YanSklyarenko I tried running it with docker-compose and it still prints the arguments. See the bottom of my answer for my minimal docker-compose file. – Hans Kilian Oct 20 '21 at 19:32
  • I mistakenly didn't mention in my initial post that I run it from inside the Visual Studio using `dvproj`. Apparently, it is VS that's causing the problem - and there's still no fix (although there's an ugly workaround: https://github.com/Microsoft/DockerTools/issues/75). So, turns out my question is just a duplicate of this one: https://stackoverflow.com/questions/52263380/how-to-pass-command-line-when-debugging-docker-compose-project-in-visual-studio. I'll update the description and close it as a duplicate, but Thank You for taking time trying to reproduce the issue! :) – Yan Sklyarenko Oct 21 '21 at 10:45
  • 1
    Finding bugs is all about forming a hypothesis and then testing to see if it's true. When your hypethesis turns out to be wrong, you then have to form a new one and in the end you find the bug :) – Hans Kilian Oct 21 '21 at 13:46