【问题标题】:Unable to run Heroku exec on a docker container无法在 docker 容器上运行 Heroku exec
【发布时间】:2019-03-05 21:07:11
【问题描述】:

我已按照此处的步骤 (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 run -a my-app bashcat /app/.profile.d/heroku-exec.sh 验证了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

【问题讨论】:

    标签: docker heroku


    【解决方案1】:

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

    而不是使用/app/.profile.d,Alpine 使用/etc/profile.d

    所以改变

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

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

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

    【讨论】:

      【解决方案2】:

      我发现我必须在基于 alpine 的 dockerfile 中额外添加一个 python 符号链接,才能使其正常工作:

      ln -s /usr/bin/python3 /usr/bin/python
      

      这是一个 dockerfile 示例,用于部署一个非常简单的 nginx 应用程序,该应用程序绝对适用于 heroku-exec(截至 2020 年 10 月):

      FROM alpine:latest
      
      # install required packages
      RUN apk add --no-cache --update python3 bash curl openssh nginx
      
      # simplfy nginx config to enable ENV variable substitution
      RUN echo 'server { listen PORT_NUMBER; }' > /etc/nginx/conf.d/default.conf \
       && mkdir /run/nginx
      
      # add config required for HEROKU_EXEC
      # ENV HEROKU_EXEC_DEBUG=1
      RUN rm /bin/sh \
       && ln -s /bin/bash /bin/sh \
       && mkdir -p /app/.profile.d/ \
       && printf '#!/usr/bin/env bash\n\nset +o posix\n\n[ -z "$SSH_CLIENT" ] && source <(curl --fail --retry 7 -sSL "$HEROKU_EXEC_URL")\n' > /app/.profile.d/heroku-exec.sh \
       && chmod +x /app/.profile.d/heroku-exec.sh \
       && ln -s /usr/bin/python3 /usr/bin/python
      
      # configure NGINX to listen on dynamic $PORT env variable supplied by Heroku.
      CMD sed -i 's/PORT_NUMBER/'"$PORT"'/g' /etc/nginx/conf.d/default.conf; nginx -g 'daemon off;'
      
      

      【讨论】:

        猜你喜欢
        • 2019-06-01
        • 1970-01-01
        • 2018-10-10
        • 2018-02-27
        • 2020-11-28
        • 1970-01-01
        • 1970-01-01
        • 2019-02-17
        • 1970-01-01
        相关资源
        最近更新 更多