-2

i have following 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"]

and want that the entrypoint.sh is executing. But i get the error:

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

what does it mean: value for switch is missing and how can i get this to run? Thanks for help

UPDATE

please see here: docker asp.net core container starting after a mysql container for more information. Sorry for a similar second thread. please delete this thread

UPDATE 2

this is my 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

it seems that dotnet ef database update doesn´t work. so i get the error msg:

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

is that not a error because the test.dll isn´t found?

eldios1981
  • 509
  • 2
  • 12
  • 26
  • Which command do you want to run in the container: 1. `/bin/bash ./app/entrypoint.sh` or 2. `dotnet test.dll` or some combination of those? – r3mus n0x Jul 16 '18 at 18:11
  • Please post the contents of `entrypoint.sh` to clarify the intended result. – r3mus n0x Jul 16 '18 at 18:22
  • sorry for the second thread. please look here: https://stackoverflow.com/questions/51359885/docker-asp-net-core-container-starting-after-a-mysql-container – eldios1981 Jul 16 '18 at 18:26

2 Answers2

2

What's happening is that dotnet test.dll is being launched with parameters /bin/bash ./app/entrypoint.sh. Then your Test program tries to parse those parameters and fails. This is what the exception is about.

You probably have to remove either CMD or ENTRYPOINT based on what you are trying to achieve. You can also swap CMD and ENTRYPOINT parameters if entrypoint.sh is intended to receive dotnet test.dll as parameters.

r3mus n0x
  • 5,954
  • 1
  • 13
  • 34
1

Because an ENTRYPOINT always prefixes the CMD, even if you change the order. So the startup command becomes this:

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

Which of course will throw an error. So you should change your dockerfile to look like this instead:

# 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"]

Should allow your container to start-up

This works because of two things.

From the question because of the order that the CMD and ENTRYPOINT have been arranged the desired command really is

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

But docker always puts the ENTRYPOINT before the CMD, no matter how they are physically arranged, so by switching the two we are able to get the desired command. Please compare the original and new dockerfile, there is only one change.

So this is a syntax issue rather than an actual technical problem, please read this stack overflow answer though https://stackoverflow.com/a/41518225/8554496

Clive Makamara
  • 2,845
  • 16
  • 31
  • Wouldn't this just pass `dotnet test.dll` to `entrypoint.sh` as parameters? Could you please explain how will this work? – r3mus n0x Jul 16 '18 at 18:34
  • thanks that works. like r3mus n0x ask. could you explain why? – eldios1981 Jul 16 '18 at 19:52
  • I've edited to try and explain why it works but it really should be straight forward, I've added a link that talks about CMD and ENTRYPOINT in detail – Clive Makamara Jul 16 '18 at 21:51
  • So in the provided link it works because the script ends with `exec "$@"` which means to execute whatever arguments are passed to the script. However in this container the script ends with `exec $run_cmd` where `run_cmd="dotnet run --server.urls http://*:80"`. So I still don't see how would it launch `dotnet test.dll`. – r3mus n0x Jul 17 '18 at 04:54
  • at least he finds the entrypoint.sh but after that i get: `SQL Server is starting up Did you mean to run dotnet SDK commands? Please install dotnet SDK from:` so its seems that the test.dll is not found – eldios1981 Jul 17 '18 at 10:50