无法在Docker容器上运行Heroku exec

时间:2018-09-30 15:52:10

标签: docker heroku

我已按照此处(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.shheroku run -a my-app bash

来验证已部署的容器上存在cat /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

2 个答案:

答案 0 :(得分:0)

“ Heroku Exec(SSH隧道)”文档的“与Docker一起使用”部分未涉及Alpine的使用。

Alpine使用/app/.profile.d而不是使用/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来做到这一点。

答案 1 :(得分:0)

我发现我必须在基于阿尔卑斯的dockerfile中另外添加一个python符号链接,以使其正常工作:

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

这是一个用于部署非常简单的nginx应用程序的dockerfile示例,该应用程序肯定与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;'

相关问题