【发布时间】:2021-07-01 06:13:47
【问题描述】:
我一直在尝试让 Flask 应用程序的这个 Ubuntu docker 映像正确构建一段时间,但它从未成功构建。我正在尝试创建一个 Python Flask 应用程序,该应用程序运行于 Flask github 存储库的分叉版本。对这个 github 存储库所做的唯一更改是在 setup.py 中,其中的依赖项被替换为其他分叉的依赖项。当我运行“docker build -t test”时。我收到以下错误:
Obtaining flask from git+git://github.com/ectoglasses/flask.git#egg=flask (from -r requirements.txt (line 6))
Cloning git://github.com/ectoglasses/flask.git to ./src/flask
Running command git clone -q git://github.com/ectoglasses/flask.git /app/src/flask
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/app/src/flask/setup.py'"'"'; __file__='"'"'/app/src/flask/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info
cwd: /app/src/flask/
Complete output (33 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/app/src/flask/setup.py", line 4, in <module>
setup(
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 144, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.8/distutils/core.py", line 121, in setup
dist.parse_config_files()
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 701, in parse_config_files
parse_configuration(self, self.command_options,
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 121, in parse_configuration
meta.parse()
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 426, in parse
section_parser_method(section_options)
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 399, in parse_section
self[name] = value
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 184, in __setitem__
value = parser(value)
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 515, in _parse_version
version = self._parse_attr(value, self.package_dir)
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 349, in _parse_attr
module = import_module(module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/src/flask/src/flask/__init__.py", line 1, in <module>
from markupsafe import escape
ModuleNotFoundError: No module named 'markupsafe'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
The command '/bin/sh -c apt-get install -y python3-pip && apt-get install -y git && pip3 install -r requirements.txt' returned a non-zero code: 1
我之前在这个项目中使用过 Alpine,但没有遇到同样的错误。我还尝试使用托管在 Pypi 上的 Flask 版本来查看问题是否出在包本身,但没有出现任何错误。这告诉我,考虑到产生这些结果的代码,这与 pip 在 Ubuntu 上的工作方式有关,我在下面发布了这些代码。
Dockerfile:
# Use Google Cloud SDK's container as the base image
FROM ubuntu:20.04
...
# Copy the contents of the current directory into the container directory /app
COPY . /app
# Set the working directory of the container to /app
WORKDIR /app
# Install the Python packages specified by requirements.txt into the container
RUN apt-get update -y
RUN apt-get install -y python3-pip && apt-get install -y git && pip3 install -r requirements.txt
CMD python3 app.py
requirements.txt:
# Python framework
-e git://github.com/ectoglasses/flask.git#egg=flask
是否有人对可能导致此错误的原因有任何想法?
【问题讨论】:
标签: python docker ubuntu flask