我只需对 Dockerfile 进行一些修改,即可在 Heroku 上使用 nginx 运行它。 Heroku 的特别之处在于,一切都以非 root 身份运行。第二个特定行为是使用来自 Heroku 本身的随机端口,并且无法修改。他们提供了 env $PORT,您应该将其绑定到 nginx。如果 Heroku 发现某些东西没有绑定到该端口,它就会停止整个容器。问题是:
如何将 nginx 绑定到给定的环境变量,以便在 nginx-site.conf 中拥有动态端口?
我尝试在以下内容中使用类似的内容Dockerfile:
env PORT;
in nginx.conf and listen PORT_from_env;
in the nginx-site.conf也尝试过listen 80;
in the nginx-site.conf and RUN /bin/sed -i "s/listen 80/listen ${PORT}/" /etc/nginx/sites-available/default.conf
in the Dockerfile
我绝对超出了我的能力范围。有人有想法或可以提供帮助吗?这将非常有帮助!
更多信息:
- https://devcenter.heroku.com/articles/dynos#web-dynos https://devcenter.heroku.com/articles/dynos#web-dynos
我通过以下方式让它为我的应用程序工作这个例子 https://github.com/rjoonas/heroku-docker-nginx-example :
Step 1:听$PORT
in default.conf.template
server {
listen $PORT default_server;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
Step 2:将此指令添加到您的Dockerfile
COPY default.conf.template /etc/nginx/conf.d/default.conf.template
Step 3:添加这个在end你的Dockerfile
CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)