Shell into a Docker container running on a Heroku dyno. How?
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.
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.
Edited:In order to run heroku ps:exec on apps with Docker and deployed via the Container Registry you have to enable runtime-heroku-exec
.You can do heroku features:enable runtime-heroku-exec
to enable it
Here you can see the documentation of exec
with the instructions to enable docker support