php - 应用程序崩溃并未能绑定 $PORT 60 秒
问题描述
我在 Heroku 中的应用程序有问题,我的设置是 Nginx、Docker 和 Php,以及一个简单的 Php 脚本。在 Heroku CLI 中发出发布命令并打开应用程序后,我的应用程序在浏览器中启动但它崩溃了。
这是日志。
2020-05-30T15:46:38.733789+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-30T15:46:51.620126+00:00 heroku[web.1]: Starting process with command `nginx -g daemon\ off\;`
2020-05-30T15:47:52.178537+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-05-30T15:47:52.210903+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-05-30T15:47:52.317640+00:00 heroku[web.1]: Process exited with status 137
2020-05-30T15:47:52.373907+00:00 heroku[web.1]: State changed from starting to crashed
Dockerfile
FROM ubuntu:latest
RUN apt-get update \
&& apt-get install -y curl zip unzip \
php7.4 php7.4-fpm \
nginx
COPY ./webapp /var/www/myapp
WORKDIR /var/www/myapp
# ADD default.conf /etc/nginx/conf.d/default.conf
COPY default.conf.template /etc/nginx/conf.d/default.conf.template
COPY nginx.conf /etc/nginx/nginx.conf
# for ubuntu
RUN useradd -m myuser
USER myuser
CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;'
更新
按照评论中的建议添加端口后,现在出现新错误
/bin/bash: envsubst: 找不到命令
解决方案
正如您在 Dockerfile 中提到的那样CMD
,$PORT
您必须在 Dockerfile 中或在运行容器时传递该环境变量。
CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;'
如果你想在 Dockerfile 中提供,
FROM ubuntu:latest
ENV PORT=80 # Add this line
...
...
CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;'
或者如果您想在运行时覆盖,请使用docker run
命令传递它
docker run -e PORT=8008 imageName
推荐阅读
- excel - 如果具有许多工作表的工作簿的 ActiveSheet 中的单元格值发生更改,则清除内容
- sql - SQL 屏蔽查询中的映射字段
- excel - IF 语句确定日期
- java - Cucumber:许多示例行 VS 许多场景大纲
- python - 枚举具有相同前缀的列
- javascript - 嵌套循环(FOR)在第二个内带有 IF 语句,仅打印一个结果
- javascript - Jest.js 错误:“已接收:序列化为相同的字符串”
- r - 如何从闪亮的应用程序中消除占位符空白?
- javascript - Array.splice 替换多个值(虽然设置为只替换一个)
- sql - SQL 按 Top 3 和其他对行进行分组。(按州和其他排名前 3 名的城市的收入)