Given a dyno in which a container is running, what's the Heroku equivalent of docker exec -it blarg /bin/bash
? That is, how can one open a shell into the already-running container?
Example Dockerfile:
FROM heroku/heroku:16
CMD while true; do sleep 1; done
Example run:
$ heroku container:push my_app
<wait a minute>
$ heroku ps
=== my_app (Free): /bin/sh -c while\ true\;\ do\ sleep\ 1\;\ done (1)
my_app.1: up 2017/10/09 12:13:07 -0600 (~ 4m ago)
So far so good.
But now...
$ heroku ps:exec --dyno=my_app.1
Establishing credentials... error
▸ Could not connect to dyno!
▸ Check if the dyno is running with `heroku ps'
For good measure I check heroku ps
at this point and it shows that the dyno is still running.
Yes, I've done all the things Heroku suggests to enable Docker support. Per the documentation, I have tried using a base image of my choice while ensuring that bash
, curl
, openssh
, and python
are present. I have also tried using the Heroku-16 base image, as shown in the above example.
(The linked documentation also references steps required for Private Spaces. Since I'm not using Private Spaces I have not applied those steps.)
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.
TL;DR Ensure that
bash
is installed in the image and add this to your Dockerfile: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:
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 doheroku features:enable runtime-heroku-exec
to enable itHere you can see the documentation of
exec
with the instructions to enable docker support