Shell 进入在 Heroku dyno 上运行的 Docker 容器.如何? [英] Shell into a Docker container running on a Heroku dyno. How?

查看:23
本文介绍了Shell 进入在 Heroku dyno 上运行的 Docker 容器.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个运行容器的 dyno,docker exec -it blarg/bin/bash 的 Heroku 等价物是什么?也就是说,如何在已经运行的容器中打开一个 shell?

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?

Dockerfile 示例:

Example Dockerfile:

FROM heroku/heroku:16
CMD while true; do sleep 1; done

示例运行:

$ 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)

到目前为止一切顺利.

但是现在...

$ heroku ps:exec --dyno=my_app.1
Establishing credentials... error
 ▸    Could not connect to dyno!
 ▸    Check if the dyno is running with `heroku ps'

此时我检查了 heroku ps,结果表明 dyno 仍在运行.

For good measure I check heroku ps at this point and it shows that the dyno is still running.

是的,我已经完成了 Heroku 建议的所有操作启用 Docker 支持.根据文档,我尝试使用我选择的基本图像,同时确保 bashcurlopensshpython 存在.我也尝试过使用 Heroku-16 基础镜像,如上例所示.

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.

(链接的文档还引用了 Private Spaces 所需的步骤.由于我没有使用 Private Spaces,所以我没有应用这些步骤.)

(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 确保 bash 已安装在映像中并将其添加到您的 Dockerfile:

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

说明

文档会让人相信的相反,Heroku不,开箱即用,支持 heroku ps:exec 进入已经在 dyno 中运行的 Docker 容器.

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.

引用我从 Heroku 团队收到的回复:

Quoting from responses I have received from the Heroku team:

我们的 ps:exec 功能...工作...通过将 bash 文件注入 dynos,在后台打开一个额外的端口,并允许您连接到它.

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]默认Docker 使用的 shell 是/bin/sh,它不兼容Heroku Exec 脚本(需要/bin/bash).

[T]he default shell used by Docker is /bin/sh, which is not compatible with the Heroku Exec script (it's requires /bin/bash).

不过,您可以使用一种解决方法.将以下内容放入您的Dockerfile:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆