uWSGI 无法在 Docker 中加载配置

uWSGI 无法在 Docker 中加载配置

我遇到了一个奇怪的问题,可能与我的 Dockerfile 有关,但我没能找到它 - 我尝试了不同的设置,但都无济于事。这是我的uwsgi.ini文件:

[uwsgi]
strict = true

socket = 0.0.0.0:8000
protocol = http

module = my_django_project.wsgi
env = DJANGO_SETTINGS_MODULE=my_django_project.settings

master = true
enable-threads = true
vacuum = true
single-interpreter = true
die-on-term = true
need-app = true

harakiri = 60

max-requests = 1000
max-worker-lifetime = 3600
reload-on-rss = 2048
worker-reload-mercy = 60

cheaper-algo = busyness
processes = 128
cheaper = 8
cheaper-initial = 16
cheaper-overload = 1
cheaper-step = 16

cheaper-busyness-multiplier = 30
cheaper-busyness-min = 20
cheaper-busyness-max = 70
cheaper-busyness-backlog-alert = 16
cheaper-busyness-backlog-step = 2

static-map = /static=/static
route = ^/healthz/?$ donotlog:
route = ^/metrics/?$ donotlog:

# spooler setup
spooler = ./spooler
spooler-processes = 2
spooler-frequency = 10

当我在 python 虚拟环境中的 VM(CentOS)上安装所有模块并运行时uwsgi --ini uwsgi.ini,一切正常,我可以在控制台输出中看到以下消息:

*** dumping internal routing table ***
[rule: 0] subject: path_info regexp: ^/healthz/?$ action: donotlog:
[rule: 1] subject: path_info regexp: ^/metrics/?$ action: donotlog:
*** end of the internal routing table ***

现在,如果我在 Docker 中运行完全相同的程序,我将收到以下错误:

web_1_c2d4cafeeae0 | [uWSGI] getting INI configuration from uwsgi.ini
web_1_c2d4cafeeae0 | [strict-mode] unknown config directive: route

这是我的Dockerfile

FROM python:3.7.5-alpine3.10

RUN set -ex && \
    apk update && \
    apk add postgresql-dev \
            gcc \
            make \
            python3-dev \
            musl-dev \
            linux-headers \
            libffi-dev \
            libxslt-dev \
            python-dev \
            libxml2 \
            libxml2-dev \
            py3-lxml && \
    pip install --upgrade pip && \
    mkdir /sources

COPY . /sources
WORKDIR /sources

RUN pip install uwsgi==2.0.18 && pip install -e . && python manage.py collectstatic --noinput

EXPOSE 8000

CMD ["uwsgi", "--ini", "uwsgi.ini"]

我尝试了不同的基础镜像,不同版本的 uwsgi(我在虚拟环境中得到了相同的结果,所以不应该是这种情况)。

如果我删除这两个指令,应用程序就可以正常工作route,但我需要它们,因为它们污染了我的记录。

为什么 uwsgi 在 Docker 中不能按预期工作?

答案1

根据这个答案,你需要将pcre-devalpine 包添加到你的 Dockerfile 中:

apk add ... \
        pcre-dev

相关内容