Nginx容器无法在Cloud Run上启动 [英] Nginx container fails to start on Cloud Run

查看:65
本文介绍了Nginx容器无法在Cloud Run上启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Cloud Run上使用Nginx提供简单的静态页面.但是容器无法正确开始投放.

I'm attempting to serve simple static page with Nginx on Cloud Run. But the container fails to properly start serving.

容器正在启动,如 docker-entrypoint.sh 所回显的调试行所示:

Container is starting, as shown by the debug lines echoed from docker-entrypoint.sh:

2019-05-26T22:19:02.340289Z testing config
2019-05-26T22:19:02.433935Z nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2019-05-26T22:19:02.434903Z nginx: configuration file /etc/nginx/nginx.conf test is successful
2019-05-26T22:19:02.436605Z starting on 8080
2019-05-26T22:19:02.487188Z2019/05/26 22:19:02 [alert] 6#6: prctl(PR_SET_DUMPABLE) failed (22: Invalid argument)

并最终终止

2019-05-26T22:20:00.153060259ZContainer terminated by the container manager on signal 9.

为了特别遵守 Cloud Run服务合同侦听 $ PORT 时, docker-entrypoint.sh 中执行 $ PORT替换conf.d/*.conf .

In order to conform with the Cloud Run service contract specifically listening on $PORT the docker-entrypoint.sh performs $PORT substitution in conf.d/*.conf.

FROM nginx:1.15-alpine

COPY nginx-default.conf.template /etc/nginx/conf.d/default.conf.template

COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]

我很自信,问题出在 docker-entrypoint.sh 之内,因为一旦$ PORT被硬编码为 8080 且图像如下所示:

I'm pretty confident issue lies within docker-entrypoint.sh because once $PORT is hardcoded as 8080 and image looks like this:

FROM nginx:1.15-alpine

COPY nginx-default.conf /etc/nginx/conf.d/default.conf

Cloud Run运行"正常.

Cloud Run "runs" fine.

执行替换的代码:

export NGINX_PORT=${PORT:-8080}
for f in $(find /etc/nginx/conf.d/ -type f -name '*.conf'); do
  envsubst '$NGINX_PORT' < $f > $f
done

注意:阅读<$ f 并编写>$ f 到同一文件的效果与通过在本地运行容器进行的测试相同.

NOTE: reading < $f and writing > $f to the same file works as tested by running the container locally.

预期

  • nginx配置获取用实际值替换的 $ PORT 占位符
  • 容器运行并在Cloud Run上的 $ PORT 上监听
  • nginx configuration gets $PORT placeholder substituted with actual values
  • container runs and listens on $PORT on Cloud Run

实际

  • 容器无法在Cloud Run上运行
  • 容器运行并在本地 $ PORT 上监听

推荐答案

已替换为固定

for f in $(find /etc/nginx/conf.d/ -type f -name '*.conf'); do
  envsubst '$NGINX_PORT' < $f > $f
done

使用

sed -i "s/\${NGINX_PORT}/${NGINX_PORT}/g" /etc/nginx/conf.d/*.conf

并更改 *.conf 文件中的 $ NGINX_PORT -> $ {NGINX_PORT} ,以避免替换歧义

and changing $NGINX_PORT -> ${NGINX_PORT} in *.conf files to avoid substitution ambiguities

这篇关于Nginx容器无法在Cloud Run上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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