我的django应用程序在docker容器内使用gunicorn运行。随机地,容器停止响应网络呼叫。容器已启动并正在运行。我已经检查了统计数据的CPU或内存使用情况,它们似乎没问题。 我的码头版:
Client:
Version: 1.13.0
API version: 1.25
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:50:17 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.0
API version: 1.25 (minimum version 1.12)
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:50:17 2017
OS/Arch: linux/amd64
Experimental: false
卷曲命令响应:
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8001 (#0)
> GET /api/health/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8001
> Accept: */*
>
未收到上述回复。虽然容器内的ping工作正常。
我的fabfile看起来像这样:
def create_gunicorn_container(tag_name, version, port, network=None):
docker_options = env.copy()
docker_options.update({'tag_name': tag_name, 'version': version, 'port': port})
if network:
docker_options['network'] = network
env.sudo(
'docker run -v %(log_root)s:/ebs1/logs --name my_app_server -p%(port)s:8001 --network=%(network)s ' \
'--env-file=%(env_file)s -itd %(DOCKER_REGISTRY)s/%(tag_name)s:%(version)s ' \
'%(gunicorn_script_path)s' % docker_options)
Docker文件:
# Dockerfile
# FROM directive instructing base image to build upon
FROM python:2-alpine
ARG req_file=requirements.txt
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements /usr/src/app/requirements
COPY requirements.txt /usr/src/app
COPY external_config /usr/src/app/external_config
RUN apk add --update bash \
&& rm -rf /var/cache/apk/* \
&& apk add --no-cache --virtual .build-deps \
build-base libxslt libxml2 libxslt-dev libxml2-dev postgresql-dev libffi-dev \
&& pip install -r $req_file \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps \
&& apk del .build-deps \
&& mkdir -p /ebs1/logs \
&& mkdir -p /var/logs/b2b \
&& mkdir -p /usr/src/scripts/
COPY myapp/ /usr/src/app/
COPY scripts /usr/src/app/scripts
VOLUME /usr/src/app/static
EXPOSE 8001
发生这种情况时,我没有看到任何泊坞日志。我为此运行docker logs b2b_app_server --follow
。此外,只有在我重新启动docker service本身之后才会修复此问题,直到那时没有为上面的curl返回任何响应。
如果它是一个已知问题,解决方案会很好,否则我应该调查所有其他参数/工具来调试或解决这个问题?
Gunicorn剧本:
from psycogreen.gevent import patch_psycopg
bind = "0.0.0.0:8001"
workers = 4
worker_class = "gevent"
timeout = 7200
loglevel = 'debug'
errorlog = "/ebs1/logs/gunicorn.error.log"
accesslog = "/ebs1/logs/gunicorn.access.log"
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
proc_name = "myapp"
def post_fork(server, worker):
# patch psycopg2 for gevent compatibility
patch_psycopg()