Shell into a Docker container running on a Heroku dyno. How?
If bash is installed, run heroku run bash
. This will get you into the shell from your command line.
You can also use the GUI and go to "More" -> "Run Console" on your heroku app, and input "bash" to bring it up there.
EDIT CIRCA 2022 This was the accepted answer in 2017. I'm not so sure anymore, so I'm unaccepting my answer here to avoid misleading anyone. I'm not fiddling with Heroku + Docker these days, so I'm not in a good position to accept an answer.
TL;DR Ensure that bash
is installed in the image and add this to your Dockerfile:
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
Explanation
Contrary to what the documentation would lead one to believe, Heroku does not, out of the box, support heroku ps:exec
into a Docker container already running in a dyno.
Quoting from responses I have received from the Heroku team:
Our ps:exec feature ... works ... by injecting a bash file into dynos, opening an additional port in the background, and allowing you to connect to it.
[T]he default shell used by Docker is /bin/sh, which is not compatible with the Heroku Exec script (it's requires /bin/bash).
There is a workaround you can use though. Put the following in your Dockerfile:
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
This is definitely a gap in our product, and we'll work to make this better.