无法容器化Flask微服务。我浏览了GitHub页面,描述了解决错误的方法,但似乎没有任何效果。我尝试了不同的python3.X-alpine运行时,但仍然是同一回事。我真的不明白为什么日志会告诉我错误:添加所需的GCC依赖项后,命令'gcc'失败,退出状态为1 。
Dockerfile
FROM python:3.7.4-alpine
RUN apk add --no-cache --virtual .build-deps gcc musl-dev \
&& pip install cython \
&& apk del .build-deps
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt --default-timeout=100 future
EXPOSE 5000
CMD ["python3", "app.py"]
错误
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ohfwxr4o/typed-ast/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ohfwxr4o/typed-ast/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-6vb5bz2_ --python-tag cp37
cwd: /tmp/pip-install-ohfwxr4o/typed-ast/
Complete output (23 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/ast3.py -> build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/conversions.py -> build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/ast27.py -> build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/__init__.py -> build/lib.linux-x86_64-3.7/typed_ast
package init file 'ast3/tests/__init__.py' not found (or not a regular file)
creating build/lib.linux-x86_64-3.7/typed_ast/tests
copying ast3/tests/test_basics.py -> build/lib.linux-x86_64-3.7/typed_ast/tests
running build_ext
building '_ast27' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/ast27
creating build/temp.linux-x86_64-3.7/ast27/Parser
creating build/temp.linux-x86_64-3.7/ast27/Python
creating build/temp.linux-x86_64-3.7/ast27/Custom
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -Iast27/Include -I/usr/local/include/python3.7m -c ast27/Parser/acceler.c -o build/temp.linux-x86_64-3.7/ast27/Parser/acceler.o
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for typed-ast
Running setup.py clean for typed-ast
Building wheel for wrapt (setup.py): started
Building wheel for wrapt (setup.py): finished with status 'done'
Created wheel for wrapt: filename=wrapt-1.11.2-cp37-none-any.whl size=19592 sha256=82243e530eafb10da7c6b0645a61b8808dcb9136c0e5787bc6c161172f7ca90d
Stored in directory: /root/.cache/pip/wheels/d7/de/2e/efa132238792efb6459a96e85916ef8597fcb3d2ae51590dfd
Successfully built future MarkupSafe wrapt
Failed to build typed-ast
Installing collected packages: future, aniso8601, wrapt, lazy-object-proxy, six, typed-ast, astroid, Click, MarkupSafe, Jinja2, itsdangerous, Werkzeug, Flask, pytz, Flask-RESTful, isort, mccabe, pylint
Running setup.py install for typed-ast: started
Running setup.py install for typed-ast: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ohfwxr4o/typed-ast/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ohfwxr4o/typed-ast/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-glxx7aqy/install-record.txt --single-version-externally-managed --compile
cwd: /tmp/pip-install-ohfwxr4o/typed-ast/
Complete output (23 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/ast3.py -> build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/conversions.py -> build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/ast27.py -> build/lib.linux-x86_64-3.7/typed_ast
copying typed_ast/__init__.py -> build/lib.linux-x86_64-3.7/typed_ast
package init file 'ast3/tests/__init__.py' not found (or not a regular file)
creating build/lib.linux-x86_64-3.7/typed_ast/tests
copying ast3/tests/test_basics.py -> build/lib.linux-x86_64-3.7/typed_ast/tests
running build_ext
building '_ast27' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/ast27
creating build/temp.linux-x86_64-3.7/ast27/Parser
creating build/temp.linux-x86_64-3.7/ast27/Python
creating build/temp.linux-x86_64-3.7/ast27/Custom
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -Iast27/Include -I/usr/local/include/python3.7m -c ast27/Parser/acceler.c -o build/temp.linux-x86_64-3.7/ast27/Parser/acceler.o
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ohfwxr4o/typed-ast/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ohfwxr4o/typed-ast/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-glxx7aqy/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
The command '/bin/sh -c pip install -r requirements.txt --default-timeout=100 future' returned a non-zero code: 1```
答案 0 :(得分:1)
在Dockerfile的开头,您卸载gcc。以后,当您安装应用程序的依赖项时,如果其中之一具有本机扩展,则会看到错误。
RUN ... apk del .build-deps
# Now gcc is gone
RUN pip install -r requirements.txt
要执行此操作,您需要将pip install
行移到apk add
和apk del
之间的块中。为了使那起作用,requirements.txt
文件必须已经在图像中。但是,您不需要整个应用程序源。如果仅在COPY
文件中requirements.txt
,则重复docker build
将在该文件已更改的情况下重新安装软件包,否则Docker的层缓存将重复使用已经存在的文件。
这应该带您到:
FROM python:3.7.4-alpine
WORKDIR /app # Docker creates this for you
COPY requirements.txt .
RUN apk add --no-cache --virtual .build-deps gcc musl-dev \
&& pip install cython \
&& pip install -r requirements.txt --default-timeout=100 future \
&& apk del .build-deps
COPY . .
EXPOSE 5000
CMD ["python3", "app.py"]