无法在 docker 容器上运行 Heroku exec

jan*_*lle 5 heroku docker

我已按照此处的步骤(https://devcenter.heroku.com/articles/exec#enabling-docker-support)安装curl (curl 7.61.1 (x86_64-alpine-linux-musl) libcurl/7.61.1 LibreSSL/2.0.0 zlib/1.2.11 libssh2/1.8.0 nghttp2/1.32.0)、python、bash 和 openssh(OpenSSH_7.2p2-hpn14v4、OpenSSL 1.0.2p 2018 年 8 月 14 日)。我已/app/.profile.d/heroku-exec.sh在容器中创建了该文件并添加了符号链接。

但是,运行heroku ps:exec -a my-app会返回以下消息:

Establishing credentials... error ! Could not connect to dyno! ! Check if the dyno is running with `heroku ps'

我已经验证我的应用程序实际上正在运行(并且启用了 runtime-heroku-exec 功能):

web (Free): /bin/sh -c exec\ java\ \$JAVA_OPTS\ -Dserver.port\=\$PORT\ -Djava.security.egd\=file:/dev/./urandom\ -jar\ /app.jar (1) web.1: up 2018/09/30 09:34:55 -0600 (~ 4m ago)

我已经通过以下heroku-exec.sh操作验证了我部署的容器中是否存在heroku run -a my-app bashcat /app/.profile.d/heroku-exec.sh

此时,我不确定要尝试什么来解决为什么 heroku exec 无法在我的容器上工作。这是我的 Dockerfile 的样子,以防我组合应用程序的方式出现问题:

FROM openjdk:8-jdk-alpine

RUN apk add --no-cache openssh-keygen
RUN apk add --no-cache openssh-client=7.2_p2-r5 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.4/main --allow-untrusted
RUN apk add --no-cache openssh-sftp-server=7.2_p2-r5 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.4/main --allow-untrusted
RUN apk add --no-cache openssh=7.2_p2-r5 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.4/main --allow-untrusted
RUN apk add --no-cache curl
RUN apk add --no-cache bash
RUN apk add --update --no-cache python
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

RUN adduser -D app-user
USER app-user

ARG JAR_FILE

ARG PORT

ARG HEROKU_FILE_NAME

COPY ${JAR_FILE} app.jar

COPY ${HEROKU_FILE_NAME} /app/.profile.d/heroku-exec.sh

ENV JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

HEALTHCHECK --interval=15m --timeout=10s --retries=3 --start-period=1m CMD curl --fail http://localhost:8080/restaurantscores/actuator/health || exit 1

CMD exec java $JAVA_OPTS -Dserver.port=$PORT -Djava.security.egd=file:/dev/./urandom -jar /app.jar
Run Code Online (Sandbox Code Playgroud)

ant*_*tor 3

“Heroku Exec(SSH 隧道)”文档的“与 Docker 一起使用”部分并未解决 Alpine 的使用问题。

而不是使用/app/.profile.dAlpine 使用/etc/profile.d.

所以改变

COPY ${HEROKU_FILE_NAME} /app/.profile.d/heroku-exec.sh
Run Code Online (Sandbox Code Playgroud)

COPY ${HEROKU_FILE_NAME} /etc/profile.d/heroku-exec.sh
Run Code Online (Sandbox Code Playgroud)

还要确保它heroku-exec.sh是可执行的。您可以使用 来执行此操作chmod +x heroku-exec.sh