我在尝试将已构建的docker镜像部署到heroku时遇到H14 Heroku错误。
由于Heroku文档说需要CMD命令,并且看起来Procfile中的命令实际上没有运行,所以我有点不知道该做什么。
我的heroku错误日志:`
2017-11-01T11:19:47.714787+00:00 app[globus.1]: Post-processed 'admin/css/forms.css' as 'admin/css/forms.2003a066ae02.css'
2017-11-01T11:19:47.715387+00:00 app[globus.1]:
2017-11-01T11:19:47.715389+00:00 app[globus.1]: 0 static files copied to '/globus/staticfiles', 62 unmodified, 24 post-processed.
2017-11-01T11:20:48.337975+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=kolland-globus-1.herokuapp.com request_id=e2a6eda9-e2bf-477b-9987-b5995d110b0e fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T11:20:48.683132+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=kolland-globus-1.herokuapp.com request_id=eb2e00ee-826a-4ddd-aa22-78e242612e8f fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T11:20:48.766644+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=kolland-globus-1.herokuapp.com request_id=60d645a6-8657-4236-80d9-7a8f8e880640 fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
输出heroku ps:
=== globus (Free): /start.sh (1)
globus.1: up 2017/11/01 13:19:44 +0200 (~ 17m ago)
应用程序的Heroku控制面板显示:
globus /start.sh
我的代码如下:
1)start.sh脚本:
#!/bin/bash
python manage.py migrate # Apply database migrations
python manage.py collectstatic --clear --noinput # clearstatic files
python manage.py collectstatic --noinput # collect static files
# Prepare log files and start outputting logs to stdout
exec gunicorn globus.wsgi --bind 0.0.0.0:$PORT --workers 3
#python manage.py runserver 0.0.0.0:$PORT --settings=globus.settings.production
2)docker-compose文件:
version: '2'
services:
globus:
build: .
image: globus:latest
ports:
- "5000:5000"
env_file: .env
volumes:
- ./globus:/opt/globus
3)Dockerfile:
FROM python:2.7.14
ENV PYTHONUNBUFFERED 1
ADD ./requirements.txt /requirements.txt
ADD ./start.sh /start.sh
ADD . /globus
RUN pip install -r requirements.txt
RUN groupadd -r django && useradd -r -g django django
RUN chown -R django /globus && chmod +x start.sh && chown django start.sh
WORKDIR /globus
CMD ["/start.sh"]
我尝试过的东西::
CMD [ "python", "./manage.py", "runserver", "0.0.0.0:$PORT", "--settings=globus.settings.production" ]
CMD ["exec", "gunicorn", "globus.wsgi", "-b", "0.0.0.0:$PORT", "--log-file", "-"]
CMD exec gunicorn globus.wsgi -b 0.0.0.0:$PORT --log-file -
CMD ["/start.sh"]
&& ENTRYPOINT ["/start.sh"](without exec gunicorn cmd) + CMD exec gunicorn globus.wsgi -b 0.0.0.0:$PORT
此外,我还在docker-compose文件中运行:
command: python manage.py runserver 0.0.0.0:$PORT --settings=globus.settings.production
command: python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT --settings=globus.settings.production
备注:
** 在本地运行docker-compose build + up适用于所有上述aproaches,前提是我将$ PORT更改为5000。 **
我觉得它可能与权限有关,因为我以root用户身份运行docker-compose build + up虽然我不确定如何更改Dockerfile以避免超出我添加的两行。
错误日志中的dyno = connect = service = 我认为这意味着应用程序以某种方式崩溃或未暴露给heroku路由器。
数据库是Heroku Postgresql Addon,凭据存储在env文件中。即使我在本地计算机上运行docker-compose,插件也能工作。
我有一个通过git部署的heroku应用程序。 当我做了一个:
heroku run bash
> ls
我可以看到文件结构 当我为这个应用程序执行相同操作时,我什么都没得到
任何帮助都将非常感谢!!!
Netstat命令的结果:
2017-11-01T20:50:11.186705+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [6] [INFO] Starting gunicorn 19.7.1
2017-11-01T20:50:11.187111+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [6] [INFO] Listening at: http://0.0.0.0:18815 (6)
2017-11-01T20:50:11.202914+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [12] [INFO] Booting worker with pid: 12
2017-11-01T20:50:11.187194+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [6] [INFO] Using worker: sync
2017-11-01T20:50:11.192252+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [11] [INFO] Booting worker with pid: 11
2017-11-01T20:50:11.247884+00:00 app[globus.1]: [2017-11-01 20:50:11 +0000] [13] [INFO] Booting worker with pid: 13
2017-11-01T20:50:16.019831+00:00 heroku[globus.1]: Process exited with status 0
2017-11-01T20:50:15.952136+00:00 app[globus.1]: (Not all processes could be identified, non-owned process info
2017-11-01T20:50:15.957398+00:00 app[globus.1]: Active Internet connections (servers and established)
2017-11-01T20:50:15.957400+00:00 app[globus.1]: Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
2017-11-01T20:50:15.952156+00:00 app[globus.1]: will not be shown, you would have to be root to see it all.)
2017-11-01T20:50:15.957400+00:00 app[globus.1]: tcp 0 0 0.0.0.0:18815 0.0.0.0:* LISTEN 6/python
2017-11-01T20:50:16.031459+00:00 heroku[globus.1]: State changed from up to crashed
2017-11-01T20:51:19.828010+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=kolland-globus-1.herokuapp.com request_id=59003956-da54-4a6f-921f-70ed4930fc3e fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T20:51:19.652507+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=kolland-globus-1.herokuapp.com request_id=6a090f48-214f-457b-9471-09e2995817fe fwd="2.87.181.37" dyno= connect= service= status=503 bytes= protocol=https