+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

如何在docker中的utf-8中运行python

发布于2021-04-30 01:22     阅读(1020)     评论(0)     点赞(9)     收藏(5)


0

1

2

3

4

5

6

7

我制作了此PoC(概念验证)代码来显示我正在处理的问题。

项目结构:

# ls -R docker_codes/
docker_codes/:
docker-compose.yml  dockerfile

dockerfile:

FROM ubuntu
RUN apt-get update
RUN apt-get install -y python3
RUN export export LC_ALL="en_US.UTF-8"
RUN python3 -c "print (u'voil\u00e0')"

docker.compose.yml

version: '3.5'
services:
  app01:
    build: 
      context: . 

命令: docker-compose up

输出错误:

Traceback (most recent call last):
  File "/bin/docker-compose", line 11, in <module>
    load_entry_point('docker-compose==1.18.0', 'console_scripts', 'docker-compose')()
  File "/usr/lib/python3.6/site-packages/compose/cli/main.py", line 71, in main
    command()
  File "/usr/lib/python3.6/site-packages/compose/cli/main.py", line 124, in perform_command
    handler(command, command_options)
  File "/usr/lib/python3.6/site-packages/compose/cli/main.py", line 959, in up
    start=not no_start
  File "/usr/lib/python3.6/site-packages/compose/project.py", line 452, in up
    svc.ensure_image_exists(do_build=do_build)
  File "/usr/lib/python3.6/site-packages/compose/service.py", line 324, in ensure_image_exists
    self.build()
  File "/usr/lib/python3.6/site-packages/compose/service.py", line 972, in build
    all_events = stream_output(build_output, sys.stdout)
  File "/usr/lib/python3.6/site-packages/compose/progress_stream.py", line 23, in stream_output
    print_output_event(event, stream, is_terminal)
  File "/usr/lib/python3.6/site-packages/compose/progress_stream.py", line 90, in print_output_event
    stream.write("%s%s" % (event['stream'], terminator))
UnicodeEncodeError: 'ascii' codec can't encode character '\xe0' in position 4: ordinal not in range(128)

该生产线"RUN export export LC_ALL="en_US.UTF-8""是围绕工作来处理这个问题,但没有sucess。

解决方案:

  • 正如来自docker-compose的github一样,这是旧版本的docker-compose的错误,如下链接https://github.com/docker/compose/issues/5678#issuecomment-365742784我的版本是docker-compose版本1.18.0,内部版本8dd22a9,更新至1.26.0时,问题消失了。

  • 旧版本使用yumhttps://download.docker.com/linux/centos/docker-ce.repo安装

  • 要获取新版本的docker-compose,请遵循:https : //docs.docker.com/compose/install/


解决方案


RUN export LC_ALL=es_US.UTF-8将不会保留在下一层中。对环境变量使用本地docker语法:ENV LC_ALL=es_US.UTF-8

并安装locales-all包装以获得国际化支持

0

1

2

3

4

5

6

7

8



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/958221/b74b264333e74434e79f/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

9 0
收藏该文
已收藏

评论内容:(最多支持255个字符)