Home > Net >  Can I shell into a worker dyno on Heroku?
Can I shell into a worker dyno on Heroku?

Time:04-25

I can shell into a Heroku app using the CLI command:

heroku run -a app-name bash

This works beautifully, however, I cannot seem to be able to specify which dyno I want to shell into. I have one web and one worker dyno, the run command always goes into the web.

Is there a solution to shell into a worker dyno?

CodePudding user response:

heroku run -a app-name bash

Actually, this doesn't "shell into" anything.

It spins up a one-off dyno, runs bash on it, and then gives you a shell. This dyno is separate from whatever running dynos you my have (web or otherwise). The shell you're in doesn't share memory, a filesystem, or anything else with your running web process, except the application slug they both use.

Your worker dyno is very similar: it is a separate dyno that doesn't share memory, a filesystem, or anything else with whatever web processes you may be running, except the application slug they both use.

With that in mind, specifying a "process" with heroku run doesn't make sense: all defined processes (web, worker, and otherwise), and the one-off dyno that gets spun up with heroku run, all start from the same place: the application slug. Then, they proceed independently. The web and worker dynos run whatever command they're assigned via your Procfile, and the one-off dyno runs whatever command was given on the command line.

I'm not sure why you want to "shell into a worker dyno", but if you add that to your question with an edit I may be able to suggest a better way of thinking about whatever problem you're trying to solve.

CodePudding user response:

I found the answer myself. Based on Docker's documentation:

If your app is composed of multiple Docker images, you can target the process type when creating a one-off dyno:

$ heroku run bash --type=worker

This works exactly as expected.

  • Related