-1

This is my CMD directive in my Dockerfile:

CMD [ "/bin/bash", "-c", "dotnet /Project/Api.dll" ]

And when I use docker exec -it to get an interactive bash into my container, I see that dotnet PID is 1.

ps -ef

This means that I can't kill it and rerun it. kill -9 1 does not work.

How can I make it not the entry process? How can I run something before it, so that I can kill it inside the container?

Big boy
  • 1,113
  • 2
  • 8
  • 23
  • The container effectively _is_ the process. You don't `docker exec` into a container to kill its main process; you just `docker stop` the container. – David Maze Apr 02 '23 at 11:22

1 Answers1

0
CMD [ "/bin/bash", "-c", "dotnet /Project/Api.dll" ]

Given command works well but as your requirement is to run this later right?

You can always write your custom shell logic/processing in a separate script and run it instead of running the above command.

This will smartly assign different pid to your dotnet process.

#!/bin/bash

#some logic
dotnet /Project/Api.dll

And you will run your script like

ENTRYPOINT ["entrypoint.sh"]

This will solve your issue to a greater extent.

Lastly to end/kill your dotnet process gracefully and not use kill command which is ultra invasive. you can use a combination of putting your dotnet app in the background and then combining it with Linux command term command which gives you a great exit/error hook to work upon.

Additionally there is this great thread about the pid1 scenario you are referring to: https://unix.stackexchange.com/questions/457649/unable-to-kill-process-with-pid-1-in-docker-container

Hope this helps.

Suchandra T
  • 569
  • 4
  • 8