dokploy icon indicating copy to clipboard operation
dokploy copied to clipboard

Request for Adding the Functionality to Terminate Container Startup Process

Open Savinykh-Sergey opened this issue 1 year ago • 11 comments

What problem will this feature address?

This feature will address the issue that arises when there are errors in the Dockerfile, causing the container to fail to start correctly due to incorrect commands. Currently, the service does not provide the ability to stop the container startup process before it completes, which can lead to the system hanging or being unable to properly handle the error.

Describe the solution you'd like

I would like to have the ability to interrupt the container startup process if it hasn't completed yet, similar to how you can stop a running container. This could be implemented in the container management interface by adding an option to "Terminate Startup," allowing the user to manually interrupt the process.

Describe alternatives you've considered

As a temporary workaround, I manually changed the container status from "Running" to "Done" in the database, which allowed me to terminate the startup process. However, this solution is inconvenient and unintuitive for most users. A simpler and more obvious method integrated into the interface would be much more useful and user-friendly.

Additional context

No response

Savinykh-Sergey avatar Aug 18 '24 12:08 Savinykh-Sergey

In order to terminate the build of any type of source it is not possible to implement because internally we use queues with redis which is used with bullmq to precisely prevent the server from freezing, and they do not offer a functionality to stop or terminate the running process unless you pay for a paid version. https://github.com/taskforcesh/bullmq/issues/632

An alternative to prevent your server from freezing in case you have very limited resources is to build the image on a ci/cd and push it to a docker registry and in dokploy simply download and run the image so you don't do the heavy process of building the image.

Siumauricio avatar Aug 19 '24 01:08 Siumauricio

@Siumauricio Let's use NATS instead of Redis. When cancellation is required, we'll send a broadcast (pub/sub) to all workers and interrupt the task. I'd like to get this functionality as soon as possible and I'm ready to write the concept. Could you reach out on Telegram for a basic consultation?

DenisVASI9 avatar Aug 19 '24 12:08 DenisVASI9

Send me a message on discord @DenisVASI9 https://discord.gg/GgfVjpff

Siumauricio avatar Aug 19 '24 14:08 Siumauricio

My npm install or bun install commands very frequently get stuck and never finish for some reason. This blocks the entire deployment pipeline on Dokploy. I've been able to kill the deployment by SSH-ing into the server and running killall docker-buildx, but it would be great to be able to do that from the dashboard, and maybe have a timeout + retry option.

verekia avatar Nov 08 '24 02:11 verekia

Read this https://github.com/Dokploy/dokploy/issues/508#issuecomment-2383740611 @verekia

Siumauricio avatar Nov 08 '24 03:11 Siumauricio

Thank you @Siumauricio. In my case the server that's building the image is not having any CPU/RAM problem at all, it's just that there is an issue in the way bun fetches, it gets stuck doing nothing, and the install never finishes. My server can handle building images, no problem.

verekia avatar Nov 08 '24 03:11 verekia

I understand @verekia , honestly I like Bun, but it has many bugs, I tried to use it in dokploy but many things didn't work for me in fact when I was creating dokploy I had this Bug https://github.com/oven-sh/bun/issues/8849 and since that moment I decided to use pnpm better

Siumauricio avatar Nov 08 '24 04:11 Siumauricio

Sure, that's fair. But the issue still stands that if the image build process hangs for any reason. Dokploy's deployment pipeline gets stuck, and nothing else can be deployed.

verekia avatar Nov 08 '24 04:11 verekia

what does this command killall docker-buildx ? it kills all the running containers or just the building containers?

Siumauricio avatar Nov 08 '24 04:11 Siumauricio

It kills the process that's building containers, not the running containers. But it's OS-dependent so it's not ideal. I tried docker buildx stop but it didn't work to stop the deployment.

verekia avatar Nov 08 '24 04:11 verekia

I think we need this functionality because I too faced an issue today.

Here is how I managed to mess it up. Pardon me for my naiveness as I'm still learning docker and experimenting with dokploy. 😅

  1. I added docker system prune -a in the custom command option available in advanced tab and clicked "Deploy".
  2. I checked the log, and saw the cmd was stuck with some question asking for me enter Y/N.
  3. Realized it was a bad idea because it blocked the whole dokploy deployment in all services.
  4. Attempted to kill the container by SSHing the server but no avail
  5. As a last attempt I just restarted my VPS from my cloud provider's dashboard which finally seemed to work.

I echo with @verekia's statement that...

the issue still stands that if the image build process hangs for any reason. Dokploy's deployment pipeline gets stuck, and nothing else can be deployed.

It would be really nice if we get some option to terminate the container startup process because it could get stuck for various reasons.

Btw appreciate the work on this project. I'm liking it so far. 😄

pratik149 avatar Dec 28 '24 22:12 pratik149

@Siumauricio revisiting this

and they do not offer a functionality to stop or terminate the running process unless you pay for a paid version

Is there a reason we can't implement this in userland? E.g. have worker processes register their PID for what task they're doing and listens to signals for interruption.

I also cross-check how Coolify implements it and I think a helper container is spun up (ghcr.io/coollabsio/coolify-helper) for deployment and uses the resource/service ID as the container name - then, when the user wants to "cancel", the helper container is simply stopped/removed.

nktnet1 avatar Apr 02 '25 22:04 nktnet1

A few days ago, I did an experiment but it failed, I tried several ways like saving the PID, and then killing it, but bullmq always keeps running. @nktnet1

Siumauricio avatar Aug 03 '25 22:08 Siumauricio

Hey @Siumauricio,

I've just made a small demo showcasing how a bullmq worker process, which spawns a docker container task, can be aborted midway, using Redis pubsub (although there can be other implementations such as polling).

https://github.com/user-attachments/assets/d9cfe97d-0b00-4163-9303-2d7f5466f384

Made it pretty quickly as a proof of concept, but hopefully it helps.

Repo:

  • https://github.com/nktnet1/bullmq-abort-demo

nktnet1 avatar Aug 03 '25 23:08 nktnet1

What helped me was to locate a building process by ps aux | grep 'docker compose' and killing it with sudo kill -9 <pid>.

luixo avatar Aug 27 '25 16:08 luixo

would love this functionality

marcopedone avatar Sep 04 '25 11:09 marcopedone

Is there any way to stop running deployments that are stuck in interactive mode? The whole service isn't working when this happens

mhbdev avatar Sep 18 '25 11:09 mhbdev

Yesterday I've got a stuck build process that never unstuck. Even after reset the process was "running" (according to dashboard) while I couldn't find any traces in ps. Only stopping the container completely and deploying again helped. Let me know if I can find any logs to provide to figure out the issue.

luixo avatar Sep 19 '25 23:09 luixo

What helped me was to locate a building process by ps aux | grep 'docker compose' and killing it with sudo kill -9 <pid>.

this works for me

quangthien27 avatar Sep 21 '25 23:09 quangthien27