Subject: Issue with uWSGI and Flask Deployment in Docker Container

Hello Docker Community,

I hope this message finds you well. I am currently facing an issue with the deployment of my Flask application within a Docker container using uWSGI. I would appreciate any insights or suggestions you may have to help me troubleshoot and resolve this problem.

Here is a brief overview of the situation:

Problem Description:

When attempting to install Flask version 2.2.3 within my Docker container, I encounter an error stating “no python instance working.” This issue seems to be related to the interaction between uWSGI and Flask, and I’m seeking guidance on how to diagnose and address the problem.

Relevant Details:

  • Dockerfile includes the necessary dependencies, including uWSGI and other required packages.
  • The application uses Flask 2.2.3 and uWSGI 2.0.19.1.
  • The uWSGI configuration (wsgi.ini) and Flask application structure seem to be in order.
  • The web application runs successfully without the specified Flask version.

Docker Compose Configuration:

I have a Docker Compose configuration with two services: one for PostgreSQL and another for the Flask web application. The web application service is dependent on the PostgreSQL service, and both services are part of a common Docker bridge network.

Additional Context:

I have verified that my Flask application code, including the uWSGI configuration, follows best practices. However, the specific error message is puzzling, and I’m unsure about the root cause.

Request for Assistance:

If anyone has encountered a similar issue or has expertise in uWSGI and Flask deployment within Docker containers, I would greatly appreciate your guidance. Are there specific considerations I should be aware of when using Flask 2.2.3 with uWSGI in a Dockerized environment?

Thank you in advance for your time and assistance. I look forward to any insights or suggestions you may provide.

Best regards,

My dockerfile:

FROM python:3.8-alpine
RUN apk update && apk add libpq
RUN apk add ca-certificates && update-ca-certificates

Change TimeZone

RUN apk add --update tzdata
ENV TZ=America/Sao_Paulo

Clean APK cache

RUN rm -rf /var/cache/apk/*
RUN apk add --virtual .build-dependencies \
–no-cache
python3-dev
musl-dev
build-base
linux-headers
pcre-dev
gcc
postgresql-dev
libffi-dev
RUN apk add --no-cache pcre
WORKDIR /app
COPY ./ /app
RUN pip install --no-cache-dir --requirement /app/requirements.txt
RUN pip install --no-cache-dir --requirement /app/version.txt
RUN apk del .build-dependencies && rm -rf /var/cache/apk/*
CMD [“uwsgi”, “–ini”, “wsgi.ini”]

My requirements.txt:

Flask==2.2.3
psycopg2==2.8.5
bcrypt==3.2.0
Flask-Login==0.5.0
requests==2.7.0
uwsgi==2.0.19.1

ISSUE:

Traceback (most recent call last):
| File “/app/./main.py”, line 3, in
| import flask
| File “/usr/local/lib/python3.8/site-packages/flask/init.py”, line 1, in
| from . import json as json
| File “/usr/local/lib/python3.8/site-packages/flask/json/init.py”, line 6, in
| from …globals import current_app
| File “/usr/local/lib/python3.8/site-packages/flask/globals.py”, line 45, in
| app_ctx: AppContext = LocalProxy( # type: ignore[assignment]
| TypeError: init() got an unexpected keyword argument ‘unbound_message’

Related StackOverflow Q&A.

1 Like

Thank you! it worked here