Dockerfile、Centos 和 Flask 的问题

Issue with Dockerfile, Centos and Flask

我有以下 Dockerfile:

FROM centos:centos7.9.2009
RUN yum update -y
RUN yum install -y python
RUN yum install -y python3-pip
RUN pip3 install flask
COPY app.py /opt/app.py
ENTRYPOINT FLASK_APP=/opt/app.py flask run --host=0.0.0.0

当我 运行 “docker 构建 . -t test123” 成功完成

但是当我 运行 “docker 运行 test123” 它失败并显示以下内容:

Traceback (most recent call last):
  File "/usr/local/bin/flask", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib64/python3.6/site-packages/flask/cli.py", line 995, in main
    cli.main(args=sys.argv[1:])
  File "/usr/local/lib64/python3.6/site-packages/flask/cli.py", line 601, in main
    return super().main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1034, in main
    _verify_python_env()
  File "/usr/local/lib/python3.6/site-packages/click/_unicodefun.py", line 100, in _verify_python_env
    raise RuntimeError("\n\n".join(extra))
RuntimeError: Click will abort further execution because Python was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/unicode-support/ for mitigation steps.

本系统列出了一些 UTF-8 支持的语言环境,您可以从中挑选。发现了以下合适的语言环境:en_US.utf8 试图添加到 Dockerfile,没有帮助

RUN export LC_CTYPE=en_US.UTF-8
RUN export LC_ALL=en_US.UTF-8

请指教,这种情况如何解决?

RUN export LC_CTYPE=en_US.UTF-8

不起作用,因为每个 RUN 语句都在孤立的 shell 中运行。命令完成后,所有设置的环境变量都将丢失。 您应该改用 ENV 语句

ENV LC_CTYPE=en_US.UTF-8