"SyntaxError: Non-UTF-8 code starting with '\xa3' in file /venv/bin/uwsgi" error when trying to launch uWSGI
Hello,
I have trying to use distroless image (python3) to run uWSGI application but the "SyntaxError: Non-UTF-8 code starting with '\xa3' in file /venv/bin/uwsgi" error causes the container to exit. The application is built as a part of a multi-stage docker build process that contains the following steps:
FROM debian:buster-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev libc-dev python3-pip build-essential python3-dev && \
python3 -m venv /venv && \
/venv/bin/pip3 install --upgrade pip && \
/venv/bin/pip3 install -U pip setuptools && \
/venv/bin/pip3 install virtualenv virtualenvwrapper && \
/venv/bin/pip3 install https://projects.unbit.it/downloads/uwsgi-lts.tar.gz
FROM build AS build-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip3 install --disable-pip-version-check -r /requirements.txt
RUN chmod +x /venv/bin/uwsgi
# Copy the virtualenv into a distroless image
FROM gcr.io/distroless/python3-debian10
COPY --from=build-venv /venv /venv
COPY . /app
WORKDIR /app
EXPOSE 8080
CMD ["/venv/bin/uwsgi", "app.ini"]
Troubleshooting steps taken:
- Tested
gcr.io/distroless/python3-debian9image - Tested
debian:stretch-slimimage - Added
RUN /venv/bin/uwsgi --helpto the first build stage to see if the application works (it does perfectly) - Tried to use iconv to convert the uwsgi file to utf-8 format (same error)
- Tried to replace the "app.ini" parameter with "--help" to isolate potential encoding issues with app.ini (same error)
- Tried to install uWSGI from requirements.txt (
uWSGI >= 2.0.19.1) - Tried to add
# coding=utf8to the first line of /venv/bin/uwsgi file (application error)
Hi!
Using provided Dockerfile I have same error as you. When I tried to override ENTRYPOINT on distroless python with ENTRYPOINT ["/venv/bin/uwsgi", "--help"] then docker run returns with /venv/bin/uwsgi: error while loading shared libraries: libpcre.so.3: cannot open shared object file: No such file or directory
Have you tried to override distroless ENTRYPOINT?
Hello @koperak ,
Thank you for your response.
In the end I tested a few other base images and python:3.7-buster AS builder turned out to be fully working.
To fix the cannot open shared object file: No such file or directory error I added COPY actions in the Dockerfile to copy the
libpcre.so.3, libxml2.so.2, libpython3.7m.so.1.0,libicui18n.so.63,libicuuc.so.63,libicudata.so.63 dependencies to the final container. Now the uWSGI works perfectly with distroless.