Docker Python set utf-8 locale

后端 未结 4 1073
星月不相逢
星月不相逢 2020-12-10 13:00

I am trying to run my python file that first reads a string in Chinese language and print it.

This is my Dockerfile

FROM python:2.7-onbuild
ENV LANG          


        
4条回答
  •  伪装坚强ぢ
    2020-12-10 13:17

    I ran into the same issue while I was deploying a Django application with supervisor and gunicorn.

    What fixed it was to add the following line to my supervisor config file:

    environment=LANG="es_ES.utf8", LC_ALL="es_ES.UTF-8", LC_LANG="es_ES.UTF-8"
    

    For your case make sure that the chinese locale that you want to print is available and installed in your docker container. This blog describes how to do it: example dockerfile (use the chinese locale instead of en_CA.UTF-8):

    FROM ubuntu:15.10
    MAINTAINER Mobify 
    
    RUN apt-get -qq update && \
        apt-get -q -y upgrade && \
        apt-get install -y sudo curl wget locales && \
        rm -rf /var/lib/apt/lists/*
    
    # Ensure that we always use UTF-8 and with Canadian English locale
    RUN locale-gen en_CA.UTF-8
    
    COPY ./default_locale /etc/default/locale
    RUN chmod 0755 /etc/default/locale
    
    ENV LC_ALL=en_CA.UTF-8
    ENV LANG=en_CA.UTF-8
    ENV LANGUAGE=en_CA.UTF-8
    

    hopefully this leads you into the right direction.

提交回复
热议问题