Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker "unsupported locale setting" when running Python container

When I try "docker run -p 8050:8050 app1" in docker I get:

Traceback (most recent call last):
File "app1.py", line 6, in <module>
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
File "/usr/local/lib/python3.6/locale.py", line 598, in setlocale
return _setlocale(category, locale)

My dockerfile looks like this:

FROM python:3.6
USER root
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get -y install locales
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 8050
ENV NAME World
CMD ["python", "app1.py"]

How can i set a local language in the app1.py without getting this error? thanks in advance

PS: Already restarted docker.

like image 656
Pedro J Asensio Avatar asked Feb 21 '19 08:02

Pedro J Asensio


1 Answers

That worked for me

RUN apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/'        /etc/locale.gen \
 && sed -i -e 's/# pt_BR.UTF-8 UTF-8/pt_BR.UTF-8 UTF-8/' /etc/locale.gen \
 && locale-gen
like image 73
Rodrigo Crispim Avatar answered Nov 09 '22 08:11

Rodrigo Crispim