Reputation: 583
Can't containerize a flask microservice. I have been through GitHub pages describing ways to solve the error but nothing seems to work.I have tried different python3.X-alpine runtimes but still the same thing. I can't really understand why the logs tell me error: command 'gcc' failed with exit status 1 when I have added the needed GCC dependicies.
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"]
Error
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```
Upvotes: 1
Views: 1078
Reputation: 158648
In the start of your Dockerfile, you uninstall gcc. When you later go to install your application's dependencies, if one of those has native extensions, you'll get the error you see.
RUN ... apk del .build-deps
# Now gcc is gone
RUN pip install -r requirements.txt
To make this work, you need to move the pip install
line into the block between the apk add
and apk del
. To make that work, the requirements.txt
file needs to be in the image already. However, you don't need the entire application source. If you COPY
in only the requirements.txt
file then repeating a docker build
will re-install packages if that file has changed, but otherwise Docker's layer caching will reuse what was already there.
This should bring you to:
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"]
Upvotes: 1