3

I have a weird problem, which is probably related to my Dockerfile, but I fail to see it - I've tried different settings, but nothing helps. Here is my uwsgi.ini file:

[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

When I'll install all modules on my VM (CentOS) in the python virtual environment and run uwsgi --ini uwsgi.ini, everything works fine and I can see the following message in the console output:

*** 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 ***

Now, if I'll run exactly the same in Docker, I'll get the following error:

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

Here is my 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"]

I've tried different base images, different versions of the uwsgi (I got the same in virtual env, so it shouldn't be the case).

The application works perfectly fine if I'll remove the two route directives, but I need them since they are polluting my logs.

Why uwsgi doesn't work as expected in Docker?

Djent
  • 99
  • 2
  • 6
  • 16
  • 2
    Did you look at this? https://stackoverflow.com/questions/27624414/enabling-internal-routing-in-uwsgi – Gerrit Dec 18 '19 at 07:40

1 Answers1

1

According to this answer, you need to add pcre-dev alpine package to your Dockerfile:

apk add ... \
        pcre-dev
mm49307
  • 111
  • 3
  • just happened to me as well: I am using the python:3.9 base image and when that changed to the latest debian (bookworm?), it broke my uwsgi. adding the libpcre3 solved it. – FuzzyAmi Jul 13 '23 at 07:58