skip to Main Content
>docker run --entrypoint "dotnet test" api-tests

This says it can’t find the executable in the path variable.

>docker run --entrypoint "dotnet" api-tests

This works but doesn’t do anything.

How do you pass multiple arguments?

e.g. dotnet test UnitTests.csproj --logger trx;LogFileName=/tests/test-results.trx

3

Answers


  1. Whatever is after the image name replaces any defined CMD and is sent as parameter to the entrypoint.

    So if you have an entrypoint defined, that you want to pass ‘dotnet test’ to, you’d do

    docker run api-tests dotnet test
    

    An example could be the alpine/curl image, that runs curl with the arguments you pass.

    docker run --rm alpine/curl -s https://www.google.com/
    

    will fetch the front page of Google. The parameters are just -s https://www.google.com/. The image has curl as the entrypoint, so you don’t need to specify that.

    Login or Signup to reply.
  2. Just add them all the way in the end.
    For ENTRYPOINT it adds to whatever was specified in the dockerfile.
    In case CMD was used it will replace it.

    so use :

    docker run api-tests test
    

    if you have ENRTYPOINT dotnet in your dockerfile.
    or:

    docker run api-tests dotnet test
    

    if you have CMD this-will-be-replaced in your dockerfile

    Login or Signup to reply.
  3. If you need the docker run --entrypoint command, only the first shell word (the actual container-side binary to run) goes there. The remaining arguments have to go after the image name, as the "command" arguments in the docker run command syntax.

    docker run 
      --entrypoint dotnet 
      api-tests 
      test UnitTests.csproj --et=cetera
    

    However, you can design your image to avoid needing this. If the image uses CMD to declare its primary command and not ENTRYPOINT, then you can similarly provide the override command in the "command" part of the docker run command.

    CMD ["dotnet", "MyApp.dll"] # and not ENTRYPOINT
    
    docker run --rm api-tests 
      dotnet test UnitTests.csproj --et=cetera
    

    I tend to reserve ENTRYPOINT for a wrapper script that ends in exec "$@", so it still runs the CMD, or for a FROM scratch image where it’s literally impossible to run anything other than the single binary in the image.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search