将shell放入Heroku dyno上运行的Docker容器中。怎么样? [英] Shell into a Docker container running on a Heroku dyno. How?
问题描述
给定一个运行容器的dyno,什么是Heroku相当于 docker exec -it blarg / bin / bash
?也就是说,如何在已经运行的容器中打开shell?
示例Dockerfile:
FROM heroku / heroku:16
CMD true;做睡1;完成
运行示例:
$ heroku container:push my_app
<等一分钟>
$ 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)
到目前为止好。
但现在...
$ heroku ps:exec --dyno = my_app.1
建立凭证...错误
▸无法连接到dyno!
▸检查dyno是否在运行'heroku ps'
heroku ps
在这一点上,它表明测功机仍在运行。
是的,我已经完成了所有Heroku建议启用Docker支持。根据文档,我已经尝试使用我选择的基础映像,同时确保 bash
, curl
, openssh
和 python
都存在。我也尝试使用Heroku-16基本镜像,如上例所示。
(链接的文档还引用了Private Spaces所需的步骤。没有使用私人空间我没有应用这些步骤。)
TL; DR确保 bash
安装在映像中,并将其添加到Dockerfile中:
pre $
RUN rm / bin / sh& &安培; ln -s / bin / bash / bin / sh
解释 p>
与文档相反会让人相信,Heroku并不支持开箱即用,支持 heroku ps:exec
到一个已经在dyno中运行的Docker容器中。
引用我从Heroku团队收到的回复:
我们的ps:exec特性...作品...通过向dynos注入bash文件,
在后台打开一个额外的端口,并允许您
连接到它。
Docker使用的默认
shell是/ bin / sh,它与
Heroku Exec脚本不兼容(它需要/ bin / bash)。
尽管您可以使用一种解决方法。将以下内容放入您的
Dockerfile中:
$ b
RUN rm / bin / sh&& ln -s / bin / bash / bin / sh
这绝对是我们产品的
差距,我们会努力做到这一点。
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.)
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.
这篇关于将shell放入Heroku dyno上运行的Docker容器中。怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!