Encoding Problems when running an app in docker (Python, Java, Ruby, …) with Ubuntu Containers (ascii, utf-8)

岁酱吖の 提交于 2019-12-18 11:46:09

问题


On my own PC the application runs nice, but when it gets deployed into docker, it fails because of invalid characters.

I am using the ubuntu:lastest container and python3, java and ruby.


回答1:


You need to set the locale correct.

This is the minimal correct Dockerfile:

FROM ubuntu:latest

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

The usual docker images don't specify a locales. You see it if you bash into it and execute locale:

sudo docker exec -i -t yowsup3 bash

Sources:

  • http://jaredmarkell.com/docker-and-locales/
  • https://github.com/docker-library/python/issues/13



回答2:


I tried the above solution and found that the locale-gen command is not available inside my docker.

so add this line above the RUN command or add it in.

RUN apt-get update && apt-get install -y locales && locale-gen en_US.UTF-8

this will now work.

and second ENV LC_ALL en_US.UTF-8 is enough to set most of the variable but it left with the two vacant so that's why we need all 3 to set.



来源:https://stackoverflow.com/questions/27931668/encoding-problems-when-running-an-app-in-docker-python-java-ruby-with-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!